首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UINavigationController怪题

UINavigationController怪题
EN

Stack Overflow用户
提问于 2013-04-21 14:15:19
回答 1查看 104关注 0票数 0

在我的应用程序中,我有NavigationController作为根目录,我还有一个导航按钮。当我按下按钮,它就会切换到另一个控制器。

目标视图代码:

代码语言:javascript
复制
- (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:

代码语言:javascript
复制
  -(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:

代码语言:javascript
复制
-(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代码,那么应用程序就会崩溃,其日志如下:

代码语言:javascript
复制
 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的代码。是什么导致了这个问题?

代码语言:javascript
复制
self.title = [unArchiver decodeObjectForKey:@"title"];

有什么问题吗?为什么它在没有navigationController和崩溃的情况下工作得很好?

我试着解决这个问题好几个小时,我尝试了各种各样的方法,我在网上阅读,但没有任何效果。我只是不知道是什么原因导致它坠毁,请帮帮忙!

EN

回答 1

Stack Overflow用户

发布于 2013-04-21 16:00:35

我想问题在于这三种说法

代码语言:javascript
复制
self.title = [unArchiver decodeObjectForKey:@"title"];
self.pubDate = [unArchiver decodeObjectForKey:@"pubdate"];
self.description = [ unArchiver decodeObjectForKey:@"description"];

试试这个:

代码语言:javascript
复制
//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"];

注意:这不是实现的方式,但这只是一种方法,以了解这些语句是否是造成您崩溃的原因。试试看,告诉我,我们找到了另一条路。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16132060

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档