我正在尝试为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'终止应用程序,原因:'尝试插入非属性列表对象( “” )用于关键notesData'
这是我的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 :(得分:0)
我认为这是错误 _notes = [[NSUserDefaults standardUserDefaults] mutableArrayValueForKey:@"的notesdata"];
也许你得到这个错误,试试这个答案 https://stackoverflow.com/a/19720674/2680768