我想知道如何在iphone的tableview中创建文本字段。
它意味着如何在uiTableviewCell上添加uitextfield以及如何处理它?</ p>
为了处理意味着在提交时回复委托和取值......
答案 0 :(得分:4)
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0,0,320,50)];
textField.tag = 1000;
[cell.contentView addSubview:textField];
[textField release];
在自定义部分,
UITextField *textField = [[cell contentView] viewWithTag:1000];
textField.text = @"Your text";
答案 1 :(得分:2)
找到以下链接
Having a UITextField in a UITableViewCell 或尝试这个
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:@"Cell"];
if( cell == nil)
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] autorelease];
cell.textLabel.text = [[NSArray arrayWithObjects:@"First",@"Second",@"Third",@"Forth",@"Fifth",@"Sixth",@"Seventh",@"Eighth",@"Nineth",@"Tenth",nil]
objectAtIndex:indexPath.row];
if (indexPath.row % 2) {
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 21)];
textField.placeholder = @"Enter Text";
textField.text = [inputTexts objectAtIndex:indexPath.row/2];
textField.tag = indexPath.row/2;
textField.delegate = self;
cell.accessoryView = textField;
[textField release];
} else
cell.accessoryView = nil;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
答案 2 :(得分:2)
在CellForRowAtIndexPath:
UITextField *textField = [UITextField alloc] initWithFrame:CGRectMake(0,0,50,50)];
cell.contentView =textField;
[textField release];
答案 3 :(得分:0)
创建UITextView或UTextField的实例,并将其作为子视图添加到UITableViewCell中。