Database Reference
In-Depth Information
This is a pretty simple method. We just remove the object from our entries array and call reloadData
on the collectionView so that our view refreshes. The final thing we need to do is add a method for
our add button.
#pragma mark - Button Methods
-(IBAction)btnAddPressed:(id)sender {
[_entries addObject:[NSString stringWithFormat:@"Friend %i",[_entries count] + 1]];
[self.collectionView reloadData];
}
We do pretty much the same thing here as we did in delete entry except we add an object to the
array instead of remove one. We use the stringWithFormat : method to create the string object by
concatenating “Friend" with the total count of the array plus one.
Our final step is to go into the storyboard and change the class for our UICollectionViewControl
and wire up our Bar Button.
Select UICollectionViewController in the Main.storyboard .
1.
Change the class to FriendsCollectionViewController .
2.
Ctrl-drag from the Bar Button item to the FriendsCollectonViewController
and select btnAddPressed: under the Sent Actions heading in the popup.
3.
FriendDetailViewController
Now we can lay the foundation for the FriendsViewController . Select the FriendsViewController.h file
and let's get to work. We start by defining the protocol for our FriendsCollectionViewControllerDelegate .
Add this line just above the @interface line.
@protocol FriendDetailViewControllerDelegate;
Next we subscribe to four delegate protocols that we use in the implementation file. They
are UITextFieldDelegate, UINavigationControllerDelegate , UIActionSheetDelegate , and
UIImagePickerControllerDelegate . One thing to note here is that we aren't actually calling any
methods on the UINavigationControllerDelegate , but the UIImagePickerControllerDelegate does
require that we subscribe to it because it will be using methods on our behalf.
@interface FriendDetailViewController : UIViewController <UITextFieldDelegate,
UINavigationControllerDelegate, UIActionSheetDelegate, UIImagePickerControllerDelegate>
Next we will define some public properties inside the interface:
@property (assign) id<FriendDetailViewControllerDelegate> delegate;
@property BOOL shouldStartEditing;
The last thing we need to do is define our actual delegate protocol. We will add a delegate method
detailViewControllerDidClose: and we will pass this controller as its parameter.
 
Search WWH ::




Custom Search