0

也许我已经看这个太久了;)我的应用程序有一个 NavigationController 和几个 ViewControllers。从两个级别的 ViewControllers 之一(mainViewController),从 rootViewController 加载,我有下面的代码。在 PushViewController 到 dataViewController 并返回(例如按下返回按钮)后,应用程序崩溃。

dataViewController 加载得很好,但是当点击 navigationController 的后退按钮时,应用程序会因对象异常而崩溃。如果我删除:

[dataViewController release];

该应用程序运行良好。这很奇怪,因为 dataViewController 是用相同的方法初始化的。有任何想法吗?

- (void) locationPage 
{

    [[NSNotificationCenter defaultCenter] postNotificationName:@"NotifyRemoveMap" object:nil];
    MyAppDelegate *app = [[UIApplication sharedApplication] delegate];

    UINavigationController *navigation = app.navigationCantroller;
    [navigation popToRootViewControllerAnimated:NO];

    DataViewController *dataViewController = [[DataViewController alloc] initWithNibName:@"DataView" bundle:nil];
    [dataViewController setCategoryId:category];

    MyLanguage *lang = app.lang;
    Mylocation *location = [lang locationForCategoryId:category];

    dataViewController.title = location.name;
    NSArray *locationArray = [lang locations];

    dataViewController.locations = locationArray;
    [navigation pushViewController:dataViewController animated:YES];
    [dataViewController release]; //  With this removed, app doesn't crash
}
4

3 回答 3

2

连你的帖子都没看。如果是 Exec-Bad-Access,我有 2 个字给你:

启用 NSZombies。

请点击此链接:(它解释了解决任何不良访问问题所需了解的所有内容)

使用 NSZombie 和 Instruments 进行手机内存调试

干杯!

于 2010-09-11T03:05:24.540 回答
1

当 dataViewController 被弹出并且您尝试访问其中的某些内容时,可能会出现问题 - 它已经被释放。您可以检查控制台以获取更多详细信息 - 更好的是,在调试模式下运行(调试配置使用调试器运行)。

您可以编辑您的问题以显示一些使用后退按钮运行的代码。

于 2010-09-10T22:04:26.063 回答
0

您谈论发布dataViewController,但您的代码说detailsViewController. 你复制和粘贴不正确还是那个错误?

您应该考虑不使用app.navigationControllerbut self.navigationController。更清洁的设计。对应用程序委托的依赖较少,它经常被用作了解太多的 frankensteinobject。

于 2010-09-10T22:06:07.610 回答