UITableView单元的就地编辑

hmt*_*hur 11 core-data objective-c uitableview

有人可以给我看一个UITableView单元的就地编辑示例...我知道UITableView委托方法,如cellForRowAtIndexPath,...等

但我不知道如何允许单元格的原位文本编辑?
也可以将此值与Core Data一起使用,即可以保留它.

我正在寻找的东西可以在设置 - > Wi-fi下看到,您可以在其中看到域,客户端,IP等字段,其中值可以在同一位置设置.

使用具有单独视图控制器的就地编辑V来控制字段值也有任何缺点吗?

Wri*_*sCS 18

添加UITextField到您的单元格.

无论您选择编辑条目,无论是使用CoreData还是存储信息,您都需要保存它.如果您使用on-Table编辑方法,则可以使用textField委托在用户返回时保存数据.

在你的cellForRowAtIndexPath:

myTextField = [[UITextField alloc] initWithFrame:CGRectMake(0,10,125,25)];
myTextField.adjustsFontSizeToFitWidth = NO;
myTextField.backgroundColor = [UIColor clearColor];
myTextField.autocorrectionType = UITextAutocorrectionTypeNo;
myTextField.autocapitalizationType = UITextAutocapitalizationTypeWords;
myTextField.textAlignment = UITextAlignmentRight;
myTextField.keyboardType = UIKeyboardTypeDefault;
myTextField.returnKeyType = UIReturnKeyDone;
myTextField.clearButtonMode = UITextFieldViewModeNever;
myTextField.delegate = self;
cell.accessoryView = myTextField;
Run Code Online (Sandbox Code Playgroud)

TextField Delegates:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if(textField == myTextField){
        /*  do your saving here  */ 
    }
}
Run Code Online (Sandbox Code Playgroud)