UINavigationController奇怪的问题

时间:2013-04-21 14:15:20

标签: iphone ios xcode uinavigationcontroller

在我的应用程序中,我将NavigationController作为root,我也有一个导航按钮。 当我按下按钮时,它会翻转到另一个控制器。

目标视图代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *filePath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]stringByAppendingPathComponent:@"favorites.plist"];
    NSData *data = [[NSData alloc]initWithContentsOfFile:filePath];
    NSKeyedUnarchiver *unArchiver = [[NSKeyedUnarchiver alloc]initForReadingWithData:data];

    self.title = [unArchiver decodeObjectForKey:@"title"];
    self.pubDate = [unArchiver decodeObjectForKey:@"pubdate"];
    self.description = [ unArchiver decodeObjectForKey:@"description"];
}

按钮代码1:

  -(void)navFavoritesButton{
    [UIView beginAnimations:@"flipview" context:nil];
    [UIView setAnimationDuration:2];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
                           forView:self.view cache:YES];
    FavoritesView *fav = [[FavoritesView alloc]initWithStyle:UITableViewStylePlain];
    UINavigationController *favNav = [[UINavigationController alloc]initWithRootViewController:fav];
    favNav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:favNav animated:YES];
}

按钮代码2:

-(void)navFavoritesButton{
    [UIView beginAnimations:@"flipview" context:nil];
    [UIView setAnimationDuration:2];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
                           forView:self.view cache:YES];
    FavoritesView *fav = [[FavoritesView alloc]initWithStyle:UITableViewStylePlain];
    fav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:fav animated:YES];

}

我有一个奇怪的问题; 如果我使用按钮2代码一切正常,视图加载,unArchived数据并将其显示在tableView上。

但如果我使用按钮1代码,应用程序会崩溃并显示以下日志:

 2013-04-21 16:51:56.714 YnetXML[21898:f803] -[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0x6b4fd30
2013-04-21 16:51:56.715 YnetXML[21898:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0x6b4fd30'
*** First throw call stack:
(0x268c052 0x1a61d0a 0x268dced 0x25f2f00 0x25f2ce2 0xc312d1 0xc9830e 0x82123 0xc9764e 0xc96c1c 0xcbd56d 0xca7d47 0xcbe441 0xcbe4f9 0xeb5c68 0xc754a1 0xc7612b 0xeb54c7 0xc9e427 0xc9e58c 0x348c4 0xc9e5cc 0x34568 0x387d 0x268dec9 0xbd45c2 0xe0fd54 0x268dec9 0xbd45c2 0xbd455a 0xc79b76 0xc7a03f 0xc792fe 0xbf9a30 0xbf9c56 0xbe0384 0xbd3aa9 0x35a9fa9 0x26601c5 0x25c5022 0x25c390a 0x25c2db4 0x25c2ccb 0x35a8879 0x35a893e 0xbd1a9b 0x22ed 0x2215)
terminate called throwing an exception(lldb)

修改

我删除了下面的行,它适用于按钮1和2代码。 应该导致什么问题?

self.title = [unArchiver decodeObjectForKey:@"title"];

可能是什么问题?为什么没有navigationController它会很好用并且崩溃?

我试图解决这个问题几个小时,我尝试了各种各样的方式,我在线阅读但没有任何作用。我只是无法弄清楚导致它崩溃的原因,请帮忙!

1 个答案:

答案 0 :(得分:0)

我猜问题就在于这三个陈述

self.title = [unArchiver decodeObjectForKey:@"title"];
self.pubDate = [unArchiver decodeObjectForKey:@"pubdate"];
self.description = [ unArchiver decodeObjectForKey:@"description"];

试试这个:

//I guess problem with this, because only when you bring in a navigation controller , your app crashes so only when navigation controller comes into play the navigation bar appears and self.title is the text you see in the center of the navigation bar - so rename self.title to self.titlesArray or something

if([[unArchiver decodeObjectForKey:@"title"] isKindOfClass:[NSString class]])
{
 //do not use self.title for other purposes, it is to set title of navigation bar.
self.title = [unArchiver decodeObjectForKey:@"title"];
}

self.pubDate = [unArchiver decodeObjectForKey:@"pubDate"];
self.description= [unArchiver decodeObjectForKey:@"description"];

注意:这不是实现的方法,但这只是一种查明这些语句是否是导致崩溃的方法。试试这个并告诉我,我们想出另一种方法。

相关问题