Database Reference
In-Depth Information
[_delegate detailViewControllerDidClose:self];
});
}];
}];
}
Here we call the
saveToURL:forSaveOperation:completionHandler:
method to save the document.
Inside our completion handler we call the
closeWithCompletionHandler:
method to close the document.
And finally inside of its completion handle we use a
dispatch_async
call against the main thread to call
our delegate method
detailViewControllerDidClose
and pass ourselves as the parameter.
The final three things we need to do are back in the
FriendsCollectionViewController.m
file so open it
back up. Let's move to our
detailViewControllerDidClose
method and adjust it to look like this.
-(void)detailViewControllerDidClose:(FriendDetailViewController *)detailViewController {
[self.navigationController popToRootViewControllerAnimated:YES];
NSFileVersion *version = [NSFileVersion currentVersionOfItemAtURL:[detailViewController.document
fileURL]];
[self addOrUpdateEntryWithURL:[detailViewController.document fileURL]
metadata:[detailViewController.document metadata] state:[detailViewController.document
documentState] version:version];
}
We are making the same call to
popToRootViewControllerAnimated
as we did previously. But now we
pull the file version of the document using the
NSFileVersion
method
currentVersionOfItemAtURL:
.
Then we call our method
addOrUpdateEntryWithURL
:
metadata
:state:
version
with all the documents
details.
Next we need to update our alert message in
entryCollectionViewCell
:
longPressedForEntry
: to
display the display name of the document we want to delete. The line where we instantiate the
UIAlertView
should now look like this:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Delete Entry" message:[NSString
stringWithFormat:@"Are you sure you want to delete the entry for %@",[[entry metadata] displayName]]
delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes",nil];
Lastly we need to update our
prepareForSegue:
method so that we pass the
selectedDocument
to
the
FriendDetailViewController
. It should now look like this:
#pragma mark - Navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"ToFriendDetails"]){
[[segue destinationViewController] setDelegate:self];
[[segue destinationViewController] setDocument:_selectedDocument];
[[segue destinationViewController] setShouldStartEditing:_shouldStartEditing];
}
}
You can now build and run your app. You should be able to save, edit, and delete documents. Next
we will add iCloud integration so that you can persist this data across all your devices.
Search WWH ::
Custom Search