2010-08-14 6 views
0

양식을 만들고 있는데 테이블 셀에서 UITextField 값을 검색하는 방법을 아는 사람이 있는지 궁금해하고있었습니다.표 셀에서 데이터 액세스

- (IBAction)saveForm:(id)sender { 
    NSLog(@"TextField Value => %@", titleField.text); 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    ... 
switch(indexPath.section) 
{ 
    case 0: 
     if (row == 0) { 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 

     CGRect titleFieldFrame = CGRectMake(20.0, 80.0, 280.0, 25.0); 
     UITextField *titleField = [[UITextField alloc] initWithFrame:titleFieldFrame]; 
     [titleField setBorderStyle:UITextBorderStyleRoundedRect]; 
     [titleField setTextColor:[UIColor blackColor]]; 
     [titleField setFont:[UIFont systemFontOfSize:16]]; 
     [titleField setPlaceholder:@"Title"]; 
     [titleField setBackgroundColor:[UIColor whiteColor]]; 
     titleField.keyboardType = UIKeyboardTypeDefault; 
     titleField.returnKeyType = UIReturnKeyDone; 
     [cell addSubview:titleField]; 
    } 
    break;  
return cell; 

}

답변

0

인스턴스 변수를 만들고 titleField를 할당하면됩니다. 또는 [titleField setTag:123] 태그를 할당 한 다음 나중에 [yourTableView viewWithTag:123]을 통해 태그를 검색 할 수 있습니다.

+0

효과가있었습니다. 나는 setTag에 관해 몰랐다. 그러나 나는 그것에 관해 더 많이 조사 할 것이고, 그것이 사용될 수 있었던 방법을 다른 방법으로 볼 것이다. DarkDust에게 감사드립니다. –

0

는, 예를 들어 titleField에 특별한 태그를 부여

UITextField *titleField = [[UITextField alloc] initWithFrame:titleFieldFrame]; 
    titleField.tag = 11280492; 

그런 다음 -viewWithTag:을 사용하여 해당보기를 가져옵니다.

-(IBAction)saveForm:(id)sender { 
    UITableViewCell* cell = ... 
    UITextField* titleField = [cell viewWithTag:11280492]; 
    NSLog(@"TextField Value => %@", titleField.text); 
} 
+0

안녕하세요 KennyTM, 도움을 주시면 감사하겠습니다. 또한 다른 태그 사용 방법을 알려 주셨습니다. DarkDust 대답은 훨씬 단순 해 보였고 또한 효과가있었습니다. 감사. –

관련 문제