【发布时间】:2009-08-04 03:34:17
【问题描述】:
我有 UITableView,它有代表玩家的自定义单元格。当我添加一个新播放器时,会添加一个新数据项并调用 [UITableView reloadData]。单元格的一部分是包含玩家名称的 UITextView。如何调出键盘?
如果我可以访问单元格中的 UITextView 但实际上尚未创建它,我可以使用 becomeFirstResponder。由于 reloadData 实际上还没有执行新单元格的创建。
以前一定有人解决过这个问题。任何有关如何完成这项工作的提示将不胜感激。
我的代码sn-p:
-(IBAction)addPlayerPressed:(id)sender {
Player *newPlayer = [Player alloc];
[players addObject:newPlayer];
[table reloadData];
// Scroll to bottom showing the new player location
NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:([players count] - 1) inSection:0];
[table scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
// cell is always nil :(
PlayerTableCell *cell = (PlayerTableCell *)[table cellForRowAtIndexPath:scrollIndexPath]
[cell.nameField setfirstResponder];
}
【问题讨论】:
标签: iphone uitableview