UITableViewCell 内的 UITextField 在 iPad 上不会激活,但在 iPhone 上可以使用
我在 UITableViewCell 中有一个 UITextField。无论我如何尝试,它都不会在 iPad 上激活(但在 iPhone 上运行良好)。点击它并告诉它成为第一个响应者都会失败。奇怪的是,如果我采用完全相同的代码并将其移动到我的应用程序中的另一个视图控制器,它执行得很好。这使得父 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;
}
帮助!
I have a UITextField inside a UITableViewCell. It will not activate on the iPad (but it works fine on the iPhone) no matter what I try. Tapping on it and telling it to become the firstResponder both fail. The odd thing is that if I take the exact same code and move it to another view controller in my app it executes just fine. This makes it seem as if there is likely a problem in the parent UITableViewController but I can't find anything obvious. I'm hoping that someone out there has experienced a similar problem and can point me in the right direction.
Below is the sample code that works fine when I move it to a new project or put it in a new view controller launched immediately by my app delegate:
// 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;
}
Help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对我来说是典型的情况,如果我只是问问题,几分钟后我就会找到答案。事实证明,我在之前的几个步骤中确实有一个视图,要求第一响应者但没有放弃。活到老,学到老!
As is typical for me if I just ask the question I find the answer a few moments later. It turns out I did have a view several steps before that had asked for the first responder but not resigned it. Live and learn!