Re: [問題] 請問TextField自動帶出鍵盤
※ 引述《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
推
07/09 23:55, , 1F
07/09 23:55, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):