繁体   English   中英

如何在tableview单元格(每行)中添加文本字段并将标记设置到每个文本字段以访问其文本

[英]how to add textfield in tableview cell(each row) and set tag to each textfield to access it's text

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

当然可以,一个小例子:

- (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];
}
...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM