Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In-place editing of UITableView cell

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?

like image 530
hmthur Avatar asked Dec 19 '10 18:12

hmthur


1 Answers

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  */ 
    }
}
like image 143
WrightsCS Avatar answered Nov 03 '22 09:11

WrightsCS