3

我在我的应用程序中使用 MGSplitViewController。从一个视图控制器,单击按钮,我将控件导航到这两种方法,其中 Formsheet 将以 MGSplitViewController 的背景打开(显示主视图和详细视图。)

这些方法运行良好,我得到了所需的结果,但经过多次操作后,应用程序在这一点上崩溃而没有打印任何日志。谁能建议我一些解决方案?

-(void)launchSplitViewWithFormSheet :(MGSplitViewController *)mGSplitViewController
{
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:mGSplitViewController];
    [self.baseNavigationController setViewControllers:[NSArray arrayWithObject:navController]]; 
    [self openFormSheet:mGSplitViewController];
}

-(void)openFormSheet:(MGSplitViewController *)mGSplitViewController
{
    DetailViewController *detailViewController = (DetailViewController *)[mGSplitViewController.viewControllers objectAtIndex:0];
    MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];

    UINavigationController *baseNavController = [[UINavigationController alloc]initWithRootViewController:masterViewController];
    detailViewController.masterViewController = detailViewController;

    baseNavController.modalPresentationStyle = UIModalPresentationFormSheet;
    [mGSplitViewController presentModalViewController:baseNavController animated:YES];    
}
4

2 回答 2

1

我自己得到了答案。代替

[self openFormSheet:mGSplitViewController];

我用线程调用了函数

    [self performSelectorOnMainThread:@selector(openPurpose:) withObject:mGSplitViewController waitUntilDone:YES];

而且我没有随机崩溃。:)

于 2012-08-19T06:31:01.953 回答
0

alloc在代码中多次调用,但您没有调用releaseautorelease在任何地方调用。每个内存分配都必须通过内存释放来平衡。如果您不这样做,您的应用程序将泄漏内存并最终崩溃。请阅读Cocoa Core Competencies 的内存管理部分

于 2012-08-16T13:21:14.770 回答