0

我已经尝试使用url 在自定义单元格中插入 uitextfield,但我不确定何时保存修改后的内容。

请让我知道并谢谢。

4

1 回答 1

1

一种方法是让您的 UITableViewController 实现 UITextFieldDelegate 协议,然后将其分配为嵌入在您的 CustomCell UITableViewCellSubclass 中的 UITextField 的委托。

您首先需要在表视图控制器子类中实现 UITextFieldDelegate 协议...

MyTableViewController : UITableViewController <UITextFieldDelegate>

然后在您的子类中为 textFieldShouldReturn:(UITextField*)textField 方法添加一个实现。当用户完成编辑单元格的 UITextField 的内容时,将调用此方法...

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    NSString *enteredText = [textField text];
    // .. do something with the text
}

最后,您需要将 CustomCell 的 UITextField 的委托属性设置为您的 UITableViewController 子类。为此,只需向现有的 tableView:cellForRowAtIndexPath: 方法添加一个方法调用...

cell.textField.delegate = self;
于 2012-05-18T08:49:57.963 回答