In-place editing of UITableView cell

前端 未结 2 436
情书的邮戳
情书的邮戳 2021-02-05 22:50

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

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-05 23:32

    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  */ 
        }
    }
    

提交回复
热议问题