-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
什么是异常消息?哪条线路崩溃? – Paulw11
如果你滚动浏览代码,我在第二个NoteDetailViewController * noteDetailViewControlelr = [segue destinationViewController];'上添加了一个笔记,但它崩溃了,并且消息是2017-04-10 19:37:20.235616-0400 final尝试[74022:7653033] [用户默认值]尝试设置非属性列表对象或libC++ abi.dylib:以NSException类型的未捕获异常终止 (lldb)我不知道哪个是 – user7847400
它不是在那条线上崩溃。设置一个异常断点。它正在崩溃,因为您正在尝试将某些东西写入不支持的用户默认值 – Paulw11