【问题标题】:My App crashing when i open new tab in tabbar iOS 6.0?当我在标签栏 iOS 6.0 中打开新标签时,我的应用程序崩溃?
【发布时间】:2013-09-05 04:28:18
【问题描述】:

我正在创建一个新闻应用,其中主要有 2 个 UIViewcontroller:

  1. 重大新闻
  2. 主页

突发新闻显示带有平铺图像和一些描述的最新消息。 在首页中,我可以选择我想要的新闻类型,例如体育、政治等。因此每次它都会在首页中显示该类型的新闻。

我的问题是

当我打开应用程序时,我可以看到突发新闻,然后我点击了一条新闻,它会在新的UIViewController 中打开,其中包含与该新闻相关的所有图片和说明。

如果我从该描述页面单击下一个标签栏按钮,它将打开主页UIViewController 并崩溃。有时我可以看到主页UIViewController,当我打开新闻时,它就崩溃了。

如果我点击后退按钮,我会到达突发新闻页面,然后它不会崩溃。

但此问题仅在 iOS 6.0+ 版本中出现。我尝试在 iOS 5.1 设备上运行相同的应用程序,它运行良好。

崩溃日志

 -[DescriptionPageViewController respondsToSelector:]: message sent to deallocated instance 0x1f59a370`

更新 刚才我尝试再次在 ipad 6.1 模拟器中使用断点运行相同的用例,但它在那里工作正常并且在没有断点设备的情况下崩溃***为什么????

Appdelegate 代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"everLaunched"]==YES) {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"everLaunched"];
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
        [[NSUserDefaults standardUserDefaults] synchronize];



            [self loadingControllers];
                    }


    return YES;

}
-(void)loadingControllers{


    BreakingNewsViewController *breaking = [[BreakingNewsViewController alloc] initWithNibName:@"BreakingNewsViewController" bundle:nil];
    UIViewController *home = [[homepage alloc] initWithNibName:@"homepage" bundle:nil];



    UINavigationController*viewController1 = [[UINavigationController alloc] initWithRootViewController:breaking];
    UINavigationController *viewController2 = [[UINavigationController alloc] initWithRootViewController:home];


    viewController1.navigationBarHidden = YES;
    viewController2.navigationBarHidden = YES;


    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:@"Tabbar_bg.png"];
    // self.tabBarController.tabBar.tintColor=[UIColor darkGrayColor];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1,
                                             viewController2
                                            ,nil];

    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    [self.tabBarController setDelegate:self];




}

【问题讨论】:

  • Crashing...crashing...crashing.. 在问题中添加崩溃日志!!
  • @Anil 在你发布之前我已经添加了日志 ok
  • 当我开始评论时它不存在..:) 你在使用 ARC 吗?
  • 请停止使用这么多大写(大喊大叫)和这么多粗体文字。这让你的问题读起来很烦人。
  • DescriptionPageViewController 对象在哪里分配和初始化?

标签: ios objective-c uiviewcontroller crash uitabbarcontroller


【解决方案1】:

您正在BreakingNewsViewController 内部分配/初始化DescriptionPageViewController

请为具有强属性的DescriptionPageViewController 对象创建属性。

 // In BreakingNewsViewController.h

@property (strong, nonatomic) DescriptionPageViewController *descriptionPageViewController;

 // In BreakingNewsViewController.m

self.descriptionPageViewController = [[DescriptionPageViewController alloc]initWithNibName:@"DescriptionPageViewController "];

【讨论】:

  • @AM 现在正在运行,你的修改
  • puneet 与您的更改应用程序在模拟器中工作..现在我正在尝试设备让我知道你的状态
  • 非常感谢 puneet 它的工作...我可以知道为什么它在崩溃之前就崩溃了吗?
  • 看看会发生什么,在 ARC 中,对象一旦使用就会被释放,如果你没有让它变得强大的话。 strong 相当于在 ARC 中保留。
  • @ok .now 我还得修复另一个崩溃 .catch u later
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-13
  • 1970-01-01
  • 1970-01-01
  • 2013-06-13
  • 2019-02-17
相关资源
最近更新 更多