Search code examples
iosuiviewcontrolleruitextfieldedituislider

Change views to edit mode in View Controller


I want to be an user to be able to enter into Edit mode when on a view controller where then they can edit the screen values which has textfields and sliders.

I followed this doc so far: https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/EnablingEditModeinaViewController/EnablingEditModeinaViewController.html

and used this part of the code

- (void)setEditing:(BOOL)flag animated:(BOOL)animated
{
    [super setEditing:flag animated:animated];
    if (flag == YES){
        // Change views to edit mode.
    }
    else {
        // Save the changes if needed and change the views to noneditable.
    }
}

how can you change views to be in edit mode? I want my user to be able to edit the input in the textFields and the value of the slider.

Thanks in advance!


Solution

  • In the if(flag == YES) part, you can set the editable property of your UITextFields to YES like so :

    textField.editable = YES;
    

    In the else part, you have to set the UITextFields back to their non-editable state like so:

    textField.editable = NO;
    

    For UISliders, use the slider.enabled property.

    I hope this helps you.