0

私のアプリでは、ルートとして NavigationController があり、ナビゲーション ボタンもあります。ボタンを押すと、別のコントローラーに切り替わります。

宛先ビュー コード:

- (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"];

何が問題なのですか?ナビゲーションコントローラーがなくてもうまく機能し、クラッシュするのはなぜですか?

私は数時間問題を解決しようとしています。あらゆる方法を試しました。オンラインで読みましたが、何も機能しません。クラッシュの原因がわかりません。助けてください!

4

1 に答える 1

0

問題はこれら3つのステートメントにあると思います

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"];

注: これは実装方法ではありませんが、これらのステートメントがクラッシュの原因であるかどうかを確認する方法にすぎません。これを試して、教えてください。別の方法を見つけます。

于 2013-04-21T16:00:35.107 に答える