开发者

UITextField inside of UITableViewCell will not activate on iPad but works on iPhone

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!


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜