如果我有一系列的表格單元格,每個表格單元格都有一個文本字段,我將如何使特定的文本字段成爲第一個響應者?如何在表格單元格中創建UITextField成爲第一響應者?
3
A
回答
4
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UITextField *textField = [[UitextField alloc] init];
...
textField.delegate = self;
textField.tag = indexPath.row;
[cell addSubView:textField];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
我希望這可以幫助你(becomeFirstResponder)文本框...
0
如果你想文本字段,成爲第一個響應加載表視圖後,
NSIndexPath *indexPath = /* Index path of the cell containg the text field */;
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// Assuming that you have set the text field's "tag" to 100
UITextField *textField = (UITextField *)[cell viewWithTag:100];
// Make it the first responder
[textField becomeFirstResponder];
0
的UITextField從UIResponder,它實現了becomeFirstResponder消息繼承。
1
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if(indexPath.row==1)
{
[cell.txtField becomeFirstResponder];
}
return cell;
}
上面的代碼將所選排在第二的UITableView cell.Thanks
0
斯威夫特4:爲了使文本框的桌面視圖中的第一響應者只需將此擴展名添加到tableView:
extension UITableView {
func becomeFirstResponderTextField() {
outer: for cell in visibleCells {
for view in cell.contentView.subviews {
if let textfield = view as? UITextField {
textfield.becomeFirstResponder()
break outer
}
}
}
}
}
然後在viewDidAppear()調用becomeFirstResponderTextField():
func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
tableView.becomeFirstResponderTextField()
}
注: 我認爲visibleCells通過
相關問題
- 1. UITextField無法在動畫製作時成爲第一響應者
- 2. 的UITextField中的UITableView不成爲第一個響應者
- 3. UITextField不會成爲收集視圖中的第一響應者
- 4. 當UITextField成爲第一響應者時自動使用鍵盤
- 5. 當UITextField成爲第一響應者時,手動滾動UITableViewController
- 6. UITextField不會退出第一響應者?
- 7. modalViewController問題與UITextField第一響應者
- 8. UITextField辭職第一響應者iOS4
- 9. 如何打破響應表格單元格中的單詞?
- 10. 如何在PHP生成表的單元格中創建鏈接?
- 11. 移動第一表格單元格成一排在N列
- 12. 使作爲第一響應者不可見的單元格的文本字段
- 13. 如何在iOS中創建多行表格單元格?
- 14. 如何在單元格中創建表格變量?
- 15. 如何在表格單元格中創建斜線
- 16. 關於表格單元格上的uitextfield
- 17. 爲java.lang.Object創建單元格
- 18. 如何檢測當UITextField是第一個響應者
- 19. 爲什麼uitextfield成爲第一響應者時永遠不會返回nil?
- 20. 如何在iOS郵件應用程序中使表格單元格響應
- 21. 如何從自定義表格單元格中的UITextField獲取事件消息到表格單元格?
- 22. 如何使用單元格在表格中創建一個字母?
- 23. 如何在觸摸tableview單元格後指定視圖作爲第一響應者?
- 24. 使UITextField從另一個類別中退出第一響應者
- 25. 在表格單元格中獲取/設置UITextField值
- 26. 在UITableViewController中重建表格單元格
- 27. 如何在表格中單元格單元格?
- 28. 基於表格第一行和表格第一列的數據創建表格
- 29. 如何檢查控件是否退出第一響應者或成爲第一響應者?
- 30. 如何爲CDE表格組件中的列單元格創建URL?
搜索這種方式,您認爲 '細胞' 有一個屬性 'txtField'。爲此,您必須創建一個自定義單元格,否則將textField作爲子視圖添加到單元格中,然後調用becomeFirstResponder。如我錯了請糾正我。 – Mat
@Mat,你說的沒錯。 –