【发布时间】:2010-10-09 10:24:03
【问题描述】:
我基本上是在尝试在 tableView:commitEditingStyle:forRowAtIndexPath: 上将 UITextField 添加到 UITableViewCell。在插入时,我想在现有单元格上添加一个 UITextField。
我用这样的方式设置了 textField:
-(void) setUpIndexField {
inputField = [[UITextField alloc] init];
inputField.textAlignment = UITextAlignmentCenter;
inputField.borderStyle = UITextBorderStyleRoundedRect;
inputField.keyboardType = UIKeyboardTypeNamePhonePad;
inputField.delegate = self;
}
然后在commitEditingStyle中,我有这样的东西:
- (void)tableView:(UITableView *)tv
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger row = [indexPath row];
if (editingStyle == UITableViewCellEditingStyleInsert) {
if (row == 0) {
UITableViewCell *cell = [tv cellForRowAtIndexPath:indexPath];
inputField.frame = [tv cellForRowAtIndexPath:indexPath].frame;
[cell.contentView addSubview:inputField];
[inputField becomeFirstResponder];
return;
}
// more code etc.
}
当我单击插入访问器 (+) 时,textField 确实会弹出到屏幕上,但在单击它的单元格附近没有。它进入 UIView 的随机部分,而不是单击 + 的 indexPath 的实际单元格。
了解我出错的地方以及如何将 UITextField 放置到单击 + 的单元格上是理想的。
【问题讨论】:
标签: ios objective-c iphone cocoa cocoa-touch