Доступ к данным из ячейки таблицы - PullRequest
0 голосов
/ 15 августа 2010

Я создаю форму, и мне было интересно, знает ли кто-нибудь, как извлечь значение 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;

}

Ответы [ 2 ]

0 голосов
/ 15 августа 2010

Вы можете просто создать переменную экземпляра и присвоить ей titleField.Или вы можете назначить тег с помощью [titleField setTag:123], а затем получить его с помощью [yourTableView viewWithTag:123].

0 голосов
/ 15 августа 2010

Присвойте тегу titleField специальный тег, например,

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

, а затем используйте -viewWithTag:, чтобы получить это представление.

...