Database Reference
In-Depth Information
The first method btnEditPressed: enables all the fields for editing by calling our enableAllFields method.
Then we create a UIBarButtonItem titled "Done" and give it an action of btnDonePressed: . We replace the
right Bar Button item with our Done button and remove the left Bar Button item. Removing the left Bar
Button item makes sure that the user is not in an edit mode when they return to the collection view.
The second method is btnDonePressed: . We disable all the fields by calling our disableAllFields
method. Then we set up the Bar Buttons back to their original state by creating an editButton and a
Back button adding those to our navigation item.
The final method is btnBackPressed: and right now it only calls our delegate method
detailViewControllerDidClose: .
The last thing we need to do is setup our viewDidLoad .
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit"
style:UIBarButtonItemStyleBordered target:self action:@selector(btnEditPressed:)];
[self.navigationItem setRightBarButtonItem:editButton];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStyleBordered target:self action:@selector(btnBackPressed:)];
[self.navigationItem setLeftBarButtonItem:backButton];
[self.navigationItem setHidesBackButton:YES];
[self configureView];
[self disableAllFields];
if(_shouldStartEditing) {
[self btnEditPressed:nil];
[_txtFirstName becomeFirstResponder];
}
}
This should be self-explanatory by now. We create our bar buttons and assign them accordingly. We
then call our configure view that sets our image border and applies our default image. We disable all
the fields so that we aren't in edit mode. Then we check to see if we shouldStartEditing and if so,
we simulate the Edit button being pressed by calling btnEditPressed: . Finally, we set the first text
field to become the first responder so that it becomes selected and the keyboard shows.
The final thing we need to do is to set up our storyboard to interact with this file.
Select the UIViewController in the storyboard and set its class to
FriendDetailViewController .
1.
In the Connections Inspector drag a connection for imgFriend ,
txtDisplayName , txtFavoriteNumber , txtFirstName , and txtLastName to the
appropriate object in the view.
2.
Next, Ctrl-drag from each of the text fields to the FriendDetailViewController
object and select delegate underneath Outlets in the popup.
3.
 
Search WWH ::




Custom Search