Re: [問題] 請問TextField自動帶出鍵盤

看板MacDev作者 (Techmemo)時間13年前 (2011/07/09 14:13), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《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
感謝T大~已經可以了~^^
07/09 23:55, 1F
文章代碼(AID): #1E5_63cM (MacDev)
文章代碼(AID): #1E5_63cM (MacDev)