我以编程方式设置了一个 UITableView,它填充了所有状态的名称。当您单击其中一个单元格时,例如。ALABAMA,将出现一个 UIAlertView 标题是您刚刚单击的状态(ALABAMA)的标题以及与该状态相关的数字,该状态位于另一个 NSMutable 数组中。每个州都有不同的数字与之相关。
这个数字实际上是 UIAlert 中的占位符文本,警报的目的是让您可以在文本字段中输入一个数字,当您点击更改按钮时,占位符文本中的数字(来自 Array ) 将随着用户估算的数字而改变;永久。一切都很好,直到我点击更改,然后我收到一个 SIGABRT 错误,并在输出中显示:
2013-02-21 20:57:33.750 final[10046:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM replaceObjectAtIndex:withObject:]: object cannot be nil'
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:[NSString stringWithFormat:@"%@", [states objectAtIndex:indexPath.row]]
message:[NSString stringWithFormat:@"%@", [tax objectAtIndex:53]]
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Change", nil];
UITextField *myTextField =[[UITextField alloc] initWithFrame:CGRectMake(42, 50, 200, 25)];
CGAffineTransform myTransform =CGAffineTransformMakeTranslation(0, 0);
[alertView setTransform:myTransform];
[myTextField setBackgroundColor:[UIColor clearColor]];
[alertView addSubview:myTextField];
myTextField.placeholder = [NSString stringWithFormat:@"%@", [tax objectAtIndex:indexPath.row]];
myTextField.borderStyle = UITextBorderStyleNone;
myTextField.returnKeyType = UIReturnKeyDone;
myTextField.textColor = [UIColor grayColor];
myTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
myTextField.textAlignment = UITextAlignmentCenter;
myTextField.delegate = self;
[alertView show];
[alertView release];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
NSString *theTaxer = [myTextField text];
[tax replaceObjectAtIndex:1 withObject:theTaxer];
}
}