2017-04-10 59 views
-1

我正在嘗試爲segue做準備,但是當我設置了VC的實例時,我得到一個線程1信號sigabrt錯誤。我導入VC,#import "NoteViewController.h"當設置視圖控制器實例的應用程序崩潰

而且在我的Segue公司準備:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
if ([segue.identifier isEqualToString:@"ShowNote"]) { 
    NoteDetailViewController *noteDetailViewController = [segue destinationViewController]; 
    NSIndexPath *selectedIndexPath = self.tableView.indexPathForSelectedRow; 
    NSInteger arrayItem = selectedIndexPath.row * 2; 
    noteDetailViewController.note = [_notes objectAtIndex:arrayItem]; 
} else if ([segue.identifier isEqualToString:@"AddNote"]) { 
    Note *note = [Note new]; 
    [self.notes addObject:note]; 
    NoteDetailViewController *noteDetailViewController = [segue destinationViewController]; // ERROR COMES HERE! 
    noteDetailViewController.note = note; 
} 
} 

我已經調試在過去的30分鐘,但我無法弄清楚發生了什麼。謝謝!

編輯:

我可能已經找到了問題;

***終止應用程序由於未捕獲的異常「NSInvalidArgumentException」,理由是:「試圖插入非財產清單對象( ‘’ )關鍵Notes數據」

這裏是我的VC代碼。

#import "NotesListTableViewController.h" 
#import "Note.h" 
#import "NoteDetailViewController.h" 

@interface NotesListTableViewController() 

@property (nonatomic, strong) NSMutableArray *notes; 

@end 

@implementation NotesListTableViewController 

- (id)initWithCoder:(NSCoder *)aDecoder { 
self = [super initWithCoder:aDecoder]; 

if (self) { 
    _notes = [[NSUserDefaults standardUserDefaults] 
       mutableArrayValueForKey:@"notesData"];; 
} 

return self; 
} 

- (void)viewWillAppear:(BOOL)animated { 
[super viewWillAppear:animated]; 

[self.tableView reloadData]; 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
// Return the number of rows in the section. 
return [self.notes count]; 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NotesCell" forIndexPath:indexPath]; 
     cell.textLabel.text = [_notes objectAtIndex:indexPath.row * 2]; 
    // cell.textLabel.text = [self.notes[indexPath.row] title]; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

return cell; 
} 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 

NSInteger titleToDelete = indexPath.row * 2; 
NSInteger messageToDelete = titleToDelete - 1; 

[_notes removeObjectAtIndex:titleToDelete]; 
[_notes removeObjectAtIndex:messageToDelete]; 
[[NSUserDefaults standardUserDefaults]setObject:_notes forKey:@"notesData"]; 

[self.notes removeObjectAtIndex:indexPath.row]; 
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 
} 



- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 

if ([segue.identifier isEqualToString:@"ShowNote"]) { 
    NoteDetailViewController *noteDetailViewController = [segue destinationViewController]; 
    NSIndexPath *selectedIndexPath = self.tableView.indexPathForSelectedRow; 
    NSInteger arrayItem = selectedIndexPath.row * 2; 
    noteDetailViewController.note = [_notes objectAtIndex:arrayItem]; 
} else if ([segue.identifier isEqualToString:@"AddNote"]) { 
    Note *note = [Note new]; 
    [self.notes addObject:note]; 
    NoteDetailViewController *noteDetailViewController = [segue destinationViewController]; 
    noteDetailViewController.note = note; 
} 
} 



- (IBAction)doneButton:(id)sender { 

[self dismissViewControllerAnimated:YES completion:nil]; 

} 

@end 
+0

什麼是異常消息?哪條線路崩潰? – Paulw11

+0

如果你滾動瀏覽代碼,我在第二個NoteDetailViewController * noteDetailViewControlelr = [segue destinationViewController];'上添加了一個筆記,但它崩潰了,並且消息是2017-04-10 19:37:20.235616-0400 final嘗試[74022:7653033] [用戶默認值]嘗試設置非屬性列表對象或libC++ abi.dylib:以NSException類型的未捕獲異常終止 (lldb)我不知道哪個是 – user7847400

+0

它不是在那條線上崩潰。設置一個異常斷點。它正在崩潰,因爲您正在嘗試將某些東西寫入不支持的用戶默認值 – Paulw11

回答

相關問題