Database Reference
In-Depth Information
_imgFriend.layer.borderColor = [UIColor darkGrayColor].CGColor;
_imgFriend.layer.borderWidth = 2.0f;
if([_document photo])
_imgFriend.image = [_document photo];
else
_imgFriend.image = [UIImage imageNamed:@"ImgNoImage"];
}
Here we are just setting up our textfields to the values inside the document and setting our photo to
the correct photo.
Our btnDone : method needs to be modified as well so that we can capture our new values from the
textfields. Add the following just below the disableAllFields call and above the creation of the
UIBarButtonItems .
[_document setFirstName:_txtFirstName.text];
[_document setLastName:_txtLastName.text];
[_document setDisplayName:_txtDisplayName.text];
[_document setFavoriteNumber:[NSNumber numberWithFloat:[_txtFavoriteNumber.text floatValue]]];
Let's modify our image picker delegate method so that we now set the photo on the document when
we have selected an image. It should now look like this.
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = (UIImage *)[info objectForKey:UIImagePickerControllerEditedImage];
UIImage *resizedImage = [image resizedImage:CGSizeMake(560, 560)
interpolationQuality:kCGInterpolationHigh];
[_document setPhoto:resizedImage];
[_imgFriend setImage:resizedImage];
[self dismissViewControllerAnimated:YES completion:nil];
}
The last thing we want to do is modify our btnBackPressed : method so that it will close the
document. Remember that we opened the document before we passed it to the view controller so
we want to make sure and close it before we go back.
-(void)btnBackPressed:(id)sender {
[_document saveToURL:[_document fileURL] forSaveOperation:UIDocumentSaveForOverwriting
completionHandler:^(BOOL success) {
[_document closeWithCompletionHandler:^(BOOL success) {
dispatch_async(dispatch_get_main_queue(), ^{
if(!success){
NSLog(@"Failed to close - %@",[_document fileURL]);
}
 
Search WWH ::




Custom Search