gpt4 book ai didi

iphone - UITableView 中的 UITextField 委托(delegate)

转载 作者:行者123 更新时间:2023-12-03 19:04:41 25 4
gpt4 key购买 nike

大家好,我正在构建一个应用程序,允许用户将数字快速输入 UITableView

我目前已经构建了框架,但在连接 View 以加载键盘并使单元格中的文本可通过用户操作进行编辑时遇到了一些麻烦。

我记得在某个地方的开发代码中有一个 iOS 示例(比如一年前,所以它不会处于 NDA 之下),您可以在其中添加项目并在 UITableView 的上下文中编辑它们> 无需进入详细的 subview 。

只需要有关如何连接委托(delegate)或如何构建代码的提示。

最佳答案

我有代码为 UITableView 创建自定义单元格,其中包含 UITextFieldUITextView 控件。在 UITableViewController 代码中我这样做:

界面

@interface MyTableViewController: 
UITableViewController <UITextFieldDelegate, UITextViewDelegate> {
....
}

实现

-(UITableViewCell *) tableView:(UItableView *) tableView 
cellForRowAtIndexPath: (NSIndexPath *) indexPath {

....

UITableViewCell * cell = ....
cell.myTextField.delegate = self;
cell.myTextField.tag = 1; //This should be unique.
return cell;
}

-(void) textFieldDidEndEditing: (UITextField * ) textField {
// Decide which text field based on it's tag and save data to the model.
}

-(void) textViewDidEndEditing: (UITextView * ) textView {
// Decide which text view based on it's tag and save data to the model.
}

关于iphone - UITableView 中的 UITextField 委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3650406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com