【发布时间】:2010-06-10 23:13:32
【问题描述】:
我在 UITableViewCell 中有一个 UITextField。无论我尝试什么,它都不会在 iPad 上激活(但在 iPhone 上可以正常工作)。点击它并告诉它成为 firstResponder 都失败了。奇怪的是,如果我采用完全相同的代码并将其移动到我的应用程序中的另一个视图控制器,它执行得很好。这看起来好像父 UITableViewController 中可能存在问题,但我找不到任何明显的东西。我希望那里有人遇到过类似的问题,并能指出我正确的方向。
以下是当我将其移至新项目或将其放入由我的应用委托立即启动的新视图控制器时可以正常工作的示例代码:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if (indexPath.row == 0) {
UITextField *nameText = [[UITextField alloc] initWithFrame:CGRectMake(5, 5, cell.contentView.frame.size.width, cell.contentView.frame.size.height)];
nameText.delegate = self;
nameText.backgroundColor = [UIColor redColor];
[cell.contentView addSubview:nameText];
[nameText becomeFirstResponder];
[nameText release];
}
// Configure the cell...
return cell;
}
救命!
【问题讨论】:
标签: iphone uitableview ipad uitextfield