Database Reference
In-Depth Information
We start out by adding a pragma mark so we can quickly find these methods from the jump bar.
The first method we implement is
collectionView:numberOfItemsInSection
. Because we are only
going to have one section, and our entries array will contain all the entries for that section, we just
pass back the total number of entries we have by using the count method on our array.
Then we implement the
numberOfSectionsInCollectionView
: method. Again, we are only going to
have one section so we send it back a value of 1.
The final method is
collectionView:cellForItemAtIndexPath:
. We start out by pulling out a
EntryCollectionViewCell from the collection
view by calling
dequeueReusableCellWithReuseId
entifier:forIndexPath
:. This method returns either a new instantiated cell or a dequeued cell that
has been prepared for reuse. Once we have the cell, we determine what entry we are concerned with
by calling
_entries[indexPath.row]
to pull our entry out of the entries array. Then we call our helper
method
configureCellForEntry:withDelegate
: and pass in the entry and ourselves as the delegate.
Finally we return our configured cell.
The next thing we want to do is add our
UICollectionViewDelegate
Methods. We are actually only
concerned with one method here which is the
collectionView:didSelectItemAtIndexPath
:.
#pragma mark - UICollectionViewDelegateFlowLayout Methods
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)
indexPath {
NSString *entry = _entries[indexPath.row];
_selectedEntry = entry;
_shouldStartEditing = NO;
[self performSegueWithIdentifier:@"ToFriendDetails" sender:nil];
}
We first get the selected entry by using the
indexPath
variable passed to us. We assign that entry to
_
selectedEntry
. We then set the _
shouldStartEditing
variable to
NO
since this is not a brand new
entry. Finally, we call
performSegueWithIdentifier:sender:
and pass it
ToFriendDetails
and nil as
the parameters.
Now let's add the
prepareForSegue
:sender: method. We won't do anything in this method except
add an
if
statement if the segue identifier is
ToFriendDetails
. This is just a stub right now, but we
will update it after we get the
FriendDetailViewController
written.
#pragma mark - Navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"ToFriendDetails"]){
}
}
Search WWH ::
Custom Search