【问题标题】:how to add textfield in tableview cell(each row) and set tag to each textfield to access it's text如何在表格视图单元格(每一行)中添加文本字段并为每个文本字段设置标签以访问它的文本
【发布时间】:2012-04-15 12:00:11
【问题描述】:

如何在表格视图单元格中添加文本字段(在每一行上)。 此文本字段将位于每行的中间。 并在单元格的每个文本字段上设置标签以访问其文本。

【问题讨论】:

标签: iphone ios uitableview uitextfield


【解决方案1】:

当然可以,举个小例子:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"test"];
    if(cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"test"] autorelease];

        UITextView *tv = [[UITextView alloc] initWithFrame:CGRectMake(0, (cell.contentView.bounds.size.height-30)/2, cell.contentView.bounds.size.width, 30)];
        [cell.contentView addSubview:tv];
        [tv setDelegate:self];
        tv.tag = indexPath.row;
    }

    return cell;
}

...
- (void)textViewDidEndEditing:(UITextView *)textView {
    NSLog(@"%d", textView.tag);

    [textView resignFirstResponder];
}
...

【讨论】:

  • 嗨朋友们,在我的逻辑中,我必须在 tableview 单元格中添加 12 个文本字段,并通过它们的标签值访问每个文本字段的文本 stackoverflow.com/questions/19621732/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多