Storing UITextField contents before view pops

后端 未结 3 504
执笔经年
执笔经年 2021-01-04 06:36

I am sure this is in the Apple documentation or must have been answered somewhere on this forum, since it seems so basic, but I could not find it nor a particularly elegant

3条回答
  •  没有蜡笔的小新
    2021-01-04 07:03

    I would think that from a UX perspective, you should display an alert to determine if the user wants to cancel the edit action they were in the middle of before exiting the current view.

    By alerting the user, you can see if they hit the button by accident or if they did decide to leave the view, take the appropriate action.

    // add this to the field(s) to be edited, selector will be called as the changes
    // are being made... still difficult to handle a cancel, but should work
    [objectToEdit addTarget:self action:@selector(updateNameField:) 
                             forControlEvents:UIControlEventEditingChanged];
    

    additional code here...

    // the method called to update object from parent view
    - (void)updateNameField:(id)sender {
        .text = ((UITextField *)sender).text;
    }
    
        

    提交回复
    热议问题