Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How I Learned to Quit Worrying and Love Storybo...

How I Learned to Quit Worrying and Love Storyboards

For a long time, I've been convinced that the only way to build iOS applications. Recently I've made the switch to use Storyboards for a project. At CocoaHeads May in Durham, NC I shared some of the things we've been doing to stay productive while working with something that was new to us.

Josh Johnson

May 22, 2014
Tweet

More Decks by Josh Johnson

Other Decks in Programming

Transcript

  1. How I Learned to Stop Worrying and Love the Storyboard

    Josh Johnson · @jnjosh · jnjosh.com
  2. Crossing to another Storyboard UIViewController *mainViewController = [[UIStoryboard storyboardWithName:@"MainWorkflow" bundle:nil]

    instantiateInitialViewController]; [self presentViewController:mainViewController animated:YES completion:nil];
  3. This can get ugly… - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { NSString

    *identifier = segue.identifier; if ([identifier isEqualToString:@"FriendsToFacebookFriends"]) { // … } else if ([identifier isEqualToString:@"FriendsToTwitterFriends"]) { // … } else if ([identifier isEqualToString:@"FriendsToContacts"]) { // … } }
  4. Dynamic Method Dispatch! - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { [self twt_prepareForSegue:segue

    sender:sender]; } /// - (void)twt_prepareForFriendsToFacebookFriendsSegue:(UIStoryboardSegue *)segue sender:(id)sender; - (void)twt_prepareForFriendsToTwitterFriendsSegue:(UIStoryboardSegue *)segue sender:(id)sender; - (void)twt_prepareForFriendsToContactsSegue:(UIStoryboardSegue *)segue sender:(id)sender;
  5. Manually Performing the Segue - (void)itemSelected:(TWTItem *)item { if ([self

    shouldPerformSegueWithIdentifier:item.segueIdentifier sender:self]) { [self performSegueWithIdentifier:item.segueIdentifier sender:self]; } }
  6. Remember Dynamic Method Dispatch? - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { [self

    twt_prepareForSegue:segue sender:sender]; } /// - (void)twt_prepareForFriendsToFacebookFriendsSegue:(UIStoryboardSegue *)segue sender:(id)sender; - (void)twt_prepareForFriendsToTwitterFriendsSegue:(UIStoryboardSegue *)segue sender:(id)sender; - (void)twt_prepareForFriendsToContactsSegue:(UIStoryboardSegue *)segue sender:(id)sender;
  7. Name your Segue Identifiers consistently static NSString *const kInviteSourceToContactsSegueIdentifier =

    @"InviteSourceToContacts"; static NSString *const kInviteSourceToFacebookSegueIdentifier = @"InviteSourceToFacebook"; static NSString *const kInviteSourceToTwitterSegueIdentifier = @"InviteSourceToTwitter"; /// - (void)twt_prepareForInviteSourceToContactsSegue:(UIStoryboardSegue *)segue sender:(id)sender;
  8. @protocol TWTNibBackedView <NSObject> + (UINib *)nib; @end /// In TWTTestCollectionViewCell

    + (UINib *)nib { return [UINib nibWithNibName:NSStringFromClass(self) bundle:nil]; } /// In TWTTestCollectionViewController -viewDidLoad [collectionView registerNib:[TWTTestCollectionViewCell nib] forCellWithReuseIdentifier:kCellIdentifier];