UITableView单元格的就地编辑 [英] In-place editing of UITableView cell

查看:163
本文介绍了UITableView单元格的就地编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



但我不知道如何允许单元格的就地文本编辑?

此值也可以与Core Data一起使用,即它可以持久化。



我在寻找的东西可以在设置 - > Wi-fi下看到,其中你可以看到域,客户端,IP等等,其中的值可以设置在同一个地方。



还有使用In-place编辑Vs有一个单独的视图控制器来控制字段值的任何缺点?

解决方案

向您的储存格添加 UITextField b
$ b

无论您使用CoreData或任何存储信息的方式,您都可以选择编辑条目,您需要在某处保存。



cellForRowAtIndexPath中,您可以使用textField委托来保存数据。

  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;

TextField代理

   - (BOOL)textFieldShouldReturn:(UITextField *)textField {
if(textField == myTextField){
/ * do您的储蓄在这里* /
}
}


Can someone please show me an example of in-place editing of UITableView cell...I am aware of UITableView delegate methods like cellForRowAtIndexPath,...etc

But I do not know how to allow for in-place text editing of cell?
Also can this value be used with Core Data i.e. can it be persisted..

The thing that I am looking for can be seen under Settings -> Wi-fi, where you see those fields Domain, Client, IP, etc where the values can be set in the same place.

Also are there are any downside of using In-place editing Vs having a separate view controller to control a field value?

解决方案

Add a UITextField to your cell.

Either way you choose to edit an entry, whether your using CoreData, or whatever to store the info, you need someway to save it. If you go the on-Table editing method, you can use the textField delegates to save the data as the user hits return.

In your 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;

TextField Delegates:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if(textField == myTextField){
        /*  do your saving here  */ 
    }
}

这篇关于UITableView单元格的就地编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆