看板 MacDev 關於我們 聯絡資訊
※ 引述《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
fatboy:感謝T大~已經可以了~^^ 07/09 23:55