UITableViewCell里面的UITextField不会在iPad上激活,但可以在iPhone上工作
问题描述:
我在UITableViewCell中有一个UITextField。无论我尝试什么,它都不会在iPad上激活(但它在iPhone上运行正常)。点击它并告诉它成为第一个响应者都失败了。奇怪的是,如果我采用完全相同的代码并将其移到另一个视图控制器中,它会执行得很好。这使得它看起来好像在父UITableViewController中可能存在问题,但我找不到任何明显的问题。我希望在那里有人遇到过类似的问题,并能指引我朝着正确的方向前进。UITableViewCell里面的UITextField不会在iPad上激活,但可以在iPhone上工作
下面是示例代码,当我把它移动到一个新的项目或把它放在我的应用程序委托立即推出了一个新的视图控制器工作正常:
// 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;
}
帮助!
答
就我而言,如果我问这个问题,我会在几分钟后找到答案。事实证明,我之前有几个步骤要求第一响应者,但没有辞职。活到老,学到老!