2

UITableViewCellに12個のUITextFields(各行に1つのテキストフィールド)を追加し、そのタグを使用して各UITextFieldのテキストにアクセスします。これどうやってするの?

4

1 に答える 1

3
UITextField *textField = (UITextField *)[cell viewWithTag:1];
// 1 is your tag, and use textField.text to get the text in the textField.

あなたのコード:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//...
nameLabel.tag =1; // 1 is your nameLabel's tag
[tv setDelegate:self];
tv.tag = indexPath.row + 1; // set it to tv.tag = indexPath.row + 2; because 1 is your nameLabel's tag

UITextField *textField = (UITextField *)[cell viewWithTag:tv.tag];//
NSLog(@"%@",textField.text);

return cell;
于 2012-05-17T13:52:36.803 に答える