【发布时间】:2011-07-14 20:48:22
【问题描述】:
我有一个表格视图,当添加一个单元格时,它不会像应用程序上已经存在的单元格那样工作。当我按下新单元格时,我的程序崩溃了,我收到了这个错误: "SIGABRT"
这是我按下单元格时的代码:
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
[self setCurrentChosenFund: [self.cells objectAtIndex:indexPath.row]];
[self setSelectedCell: [tableView cellForRowAtIndexPath:indexPath]];
if ([self.currentChosenFund valueForKey:@"Selected"] == [NSNumber
numberWithBool:YES])
{
//selectedCell.imageView.image = [UIImage imageNamed:@"checklist.png"];
[self.selectedCell setAccessoryType: UITableViewCellAccessoryNone];
[self.currentChosenFund setObject:[NSNumber numberWithBool:NO]
forKey:@"Selected"]; // ERROR IS ON THIS LINE :(
}
else
{
//selectedCell.imageView.image = nil;
[self.selectedCell setAccessoryType: UITableViewCellAccessoryCheckmark];
[self.currentChosenFund setObject:[NSNumber numberWithBool:YES]
forKey:@"Selected"];
}
[[NSUserDefaults standardUserDefaults] setObject:self.cells forKey:@"funds"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
有谁知道如何解决这个问题?
save: 方法的代码是:
- (IBAction)saveButton:(id)sender {
NSLog(@"%@", textField.text);
CheckListPracticeViewController * obj = (CheckListPracticeViewController
*)self.parentViewController;
[obj.cells insertObject:[NSDictionary dictionaryWithObject:textField.text
forKey:@"name"] atIndex:0];
// [obj.cells insertObject:textField.text atIndex:0];
[self dismissModalViewControllerAnimated:YES];
}
好的,所以我将这行代码添加到我的 saveButton: 方法中:
[self.currentChosenFund setObject:[NSNumber numberWithBool:NO]
forKey:@"Selected"];
我仍然让应用程序崩溃!我尝试将其设置为 YES 和 NO,但它不起作用。
【问题讨论】:
-
崩溃时的信息是什么?你能发布堆栈跟踪吗?
-
你能把整个错误信息贴出来吗?
-
self.currentChosenFund是可变集合的实例吗? -
是的,整个消息是“线程 1:程序收到信号:SIGABRT”,是的,currentChosenFund 是一个可变数组!
标签: iphone xcode4 uitableview