프로그래밍 방식으로 UITableView를 설정하고 상태의 모든 이름으로 채 웁니다. 세포 중 하나를 클릭하면 예를 들어. ALABAMA, UIAlertView가 나타납니다. 제목은 방금 클릭 한 상태 (ALABAMA)이고 다른 NSMutable 배열에있는 해당 상태와 관련된 숫자입니다. 모든 주마다 서로 다른 번호가 있습니다.UIAlertView에서 단추를 눌러 NSArray를 변경하는 작업이 필요합니다.
이 번호는 실제로 UIAlert의 자리 표시 자 텍스트이며 경고의 목적은 텍스트 필드에 숫자를 입력 할 수있게하고 CHANGE 버튼을 누르면 자리 표시 자 텍스트에 있던 번호입니다 (배열에서) 사용자가 입력 한 번호로 변경됩니다. 영구히. 나는 변화를 명중 할 때까지 모두가 좋은, 그리고 나는 SIGABRT 오류가 발생, 출력에 읽기 없습니다 :
alertView 지점에서 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];
}
}