2013-02-22 3 views
-1

프로그래밍 방식으로 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]; 
    } 
} 

답변

0

: clickedBUttonAtIndex이 myTextField라고 더 이상 myTextField 때문에 정의된다 클래스 ivar로 정의되지 않은 경우 클래스를 만든 함수에서 만 참조 할 수 있습니다. 클래스의 다른 위치 (예 : alertView 콜백)에서 myTextField을 참조하려는 경우 클래스 iVar로 만듭니다.

0

Shizam이 맞습니다. 텍스트보기의 참조를 얻으려면 다음과 같이 alertview를 작성할 때 textview에 태그를 지정하십시오. myTextField.tag = 111; 다음 alertView 위임 방법 :

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 

if (buttonIndex == 1) { 

    UITextField *textField = [alertView viewWithTag:111]; 
    NSString *theTaxer = [textField text]; 
    [tax replaceObjectAtIndex:1 withObject:theTaxer]; 
} 
} 
0

이 시도

- (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]; 
alertView.tag =indexPath.row; 

UITextField *myTextField =[[UITextField alloc] initWithFrame:CGRectMake(42, 50, 200, 25)]; 
[myTextField setTag:99]; 
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) { 
    UITextField * myTextField = (UITextField *)[alertView viewWithTag:99]; 
    NSString *theTaxer = [myTextField text]; 
    [tax replaceObjectAtIndex:1 withObject:theTaxer]; 
} 
} 
관련 문제