【发布时间】:2012-04-15 12:00:11
【问题描述】:
如何在表格视图单元格中添加文本字段(在每一行上)。 此文本字段将位于每行的中间。 并在单元格的每个文本字段上设置标签以访问其文本。
【问题讨论】:
-
朋友们可以在这里添加多个文本字段stackoverflow.com/questions/19621732/…
标签: iphone ios uitableview uitextfield
如何在表格视图单元格中添加文本字段(在每一行上)。 此文本字段将位于每行的中间。 并在单元格的每个文本字段上设置标签以访问其文本。
【问题讨论】:
标签: iphone ios uitableview uitextfield
当然可以,举个小例子:
- (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];
}
...
【讨论】: