2014-04-29 1 views
0

나는 UITableView을 가지고 있는데, 이는 이름 목록을 의미합니다. 이름을 클릭 할 때마다 UIAlertView을 불러와 이름과 관련된 정보 (지금은 나이) 만 변경할 수 있도록하고 싶습니다.경고보기에 텍스트를 보관하고 텍스트를 NSString에 저장 하시겠습니까?

는 지금, 나는 당신이 자리에 UITextField 재설정 내부의 alertView의 text을 닫습니다 그러나되면, UITextFieldalertView가 나타날 수 있습니다. 텍스트를 UIAlertView에 머무르게하려면 어떻게해야합니까? 또한

- (void)tableView:(UITableView *)tableView 
     didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    UIAlertView *alert = 
    [[UIAlertView alloc] initWithTitle:@"Set Age" 
           message:[_tableData1 objectAtIndex:indexPath.row] 
           delegate:nil 
        cancelButtonTitle:@"OK" 
        otherButtonTitles:nil]; 

    alert.alertViewStyle = UIAlertViewStylePlainTextInput; 
    UITextField *textField = [alert textFieldAtIndex:0]; 
    textField.placeholder = @"18"; 
    [alert show]; 
} 

, 내가 어떻게 UIAlertView에서 텍스트를 얻을, 그리고 NSString로 저장할 수 있습니다?

감사합니다.

+0

UIAlertViewDelegate을 추가해야'alertView : clickedButtonAtIndex를'그'UITextField' 텍스트를 검색 할 수 있습니다. – Larme

답변

0

보기 컨트롤러를 위임자로 설정 한 다음 콜백에서 값을 검색해야합니다. 당신은 또한`UIAlertView`의 대리자 메서드에 @interface

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Set Age" message:[_tableData1 objectAtIndex:indexPath.row] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

    alert.alertViewStyle = UIAlertViewStylePlainTextInput; 
    UITextField *textField = [alert textFieldAtIndex:0]; 
    textField.placeholder = @"18"; 
    [alert show]; 
} 


-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { 
    if(buttonIndex == alertView.cancelButtonIndex) { 
     return; 
    } 

    NSString * yourString = [alertView textFieldAtIndex:0].text 

} 
+0

'initWithTitle : message : delegate : cancelButtonTitle : otherButtonTitles' 메소드에서 델리게이트를 설정할 수 있습니다. –

+0

@Catalyst - 네 감사합니다. 답변을 업데이트하겠습니다. – Flexicoder

관련 문제