作者Techmemo (Techmemo)
看板MacDev
标题Re: [问题] 请问TextField自动带出键盘
时间Sat Jul 9 14:13:20 2011
※ 引述《fatboy (胖孩子)》之铭言:
要让 keyboard出现执行 [textField becomeFirstResponder]; 是没错的,
但是他把 accessoryView 等於 textField
似乎会造成某些 event 被预设的 accesoryView or TableView 吃掉,
如果用
[cell.contentView addSubview:textField];
[textField becomeFirstResponder];
就不会有问题了。
: 小弟正在学习如何写iPhone app
: 可是遇到了点问题@@
: 我现在想要做的事情是:
: 按下一个按钮,会在TableView中把Cell.AccessoryView=UITextField
: 可是想要让这个UITextField直接取得焦点,好让键盘自动跑出来
: 可是怎麽试都试不出来@@
: 以下是程式片段:
: UITableViewCell *addCell = [tableView cellForRowAtIndexPath:indexPath];
: UITextField *textField = [[[UITextField alloc]
: initWithFrame:CGRectMake(0, 0, 300, 22)] autorelease];
: textField.placeholder = @"Enter you wanna add.";
: textField.enabled = YES;
: addCell.accessoryView = textField;
: [addCell.accessoryView becomeFirstResponder];
: [textField addTarget:self action:@selector(saveIt:)
: forControlEvents:UIControlEventEditingDidEndOnExit];
: 不知道是哪边写错了@@
: 再请各位大大指点一番~感谢!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 111.81.80.107
1F:推 fatboy:感谢T大~已经可以了~^^ 07/09 23:55