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

iOS Training Part 2

iOS Training Part 2

Part 2 of iOS Training for Mobile March 2012

Sam Kirchmeier

May 07, 2012
Tweet

More Decks by Sam Kirchmeier

Other Decks in Programming

Transcript

  1. iOS Training Part 2 Sam Kirchmeier [email protected] @skirchmeier Monday, May

    7, 12
  2. Getting Started •MobileMarch_Part_2_Start •https://github.com/skirchmeier/ mobilemarch-2012-ios Monday, May 7, 12

  3. •MobileMarch_Part_2_Start •https://github.com/skirchmeier/ mobilemarch-2012-ios Monday, May 7, 12

  4. Topics •Storyboards •Navigation Controllers •Table View Controllers Monday, May 7,

    12
  5. Goals 1. Display a list of tomorrow’s sessions 2. Display

    a live Twitter feed 3. Bask in the glory of our iOS prowess Monday, May 7, 12
  6. Storyboards Monday, May 7, 12

  7. Scenes View Controllers Segues Transitions Monday, May 7, 12

  8. Monday, May 7, 12

  9. Scene Monday, May 7, 12

  10. Scene Segue Monday, May 7, 12

  11. Segues - (IBAction)showAboutView:(id)sender { // Use presentModalViewController to // display

    the view controller. } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Grab a reference to the view controller via // [segue destinationViewController]. } Old Way New Way Monday, May 7, 12
  12. Demo Monday, May 7, 12

  13. Goal #1 Display a list of sessions Monday, May 7,

    12
  14. Navigation Controller Monday, May 7, 12

  15. Monday, May 7, 12

  16. Monday, May 7, 12

  17. View Controller 1 View Controller 2 Monday, May 7, 12

  18. Demo Monday, May 7, 12

  19. Table View Controller Monday, May 7, 12

  20. Monday, May 7, 12

  21. Monday, May 7, 12

  22. Navigation Controller Monday, May 7, 12

  23. Navigation Controller View Controller Monday, May 7, 12

  24. Navigation Controller View Controller Table View Monday, May 7, 12

  25. Navigation Controller View Controller Table View Navigation Controller Table View

    Controller Table View Built In Monday, May 7, 12
  26. Navigation Controller View Controller Table View Monday, May 7, 12

  27. Navigation Controller View Controller Table View Delegate Data Source Monday,

    May 7, 12
  28. Navigation Controller View Controller Table View Delegate Data Source Data

    Source Object Number of rows Number of sections Data to display in each row Monday, May 7, 12
  29. Navigation Controller View Controller Table View Delegate Object Handle touch

    events Header and footer views Rearrange rows Delegate Data Source Data Source Object Number of rows Number of sections Data to display in each row Monday, May 7, 12
  30. Navigation Controller View Controller Table View Delegate Object Handle touch

    events Header and footer views Rearrange rows Delegate Data Source Data Source Object Number of rows Number of sections Data to display in each row UITableViewDataSource UITableViewDelegate Monday, May 7, 12
  31. Navigation Controller Table View Controller Table View Built In Monday,

    May 7, 12
  32. Navigation Controller Table View Controller Table View Built In Data

    Source Delegate Monday, May 7, 12
  33. UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number

    of rows here. } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // Configure the cell here. return cell; } Monday, May 7, 12
  34. UITableViewDelegate – tableView:didSelectRowAtIndexPath: – tableView:heightForRowAtIndexPath: – tableView:viewForHeaderInSection: – tableView:viewForFooterInSection: (and

    lots more) Monday, May 7, 12
  35. UITableViewCell Monday, May 7, 12

  36. Basic Monday, May 7, 12

  37. Right Detail Monday, May 7, 12

  38. Left Detail Monday, May 7, 12

  39. Subtitle Monday, May 7, 12

  40. Demo Monday, May 7, 12

  41. Goal #2 Display a Twitter feed Monday, May 7, 12

  42. Twitter Framework Monday, May 7, 12

  43. TWRequest TWRequest *request = [[TWRequest alloc] initWithURL:URL parameters:parameters requestMethod:TWRequestMethodGET]; [request

    performRequestWithHandler:^( NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { // Invoked after the response is complete. // Parse response and display tweets. }]; Monday, May 7, 12
  44. ^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { // Invoked after

    the response is complete. // Parse response and display tweets. } Request Handler Block [request performRequestWithHandler: ]; Request Handler Block Monday, May 7, 12
  45. Threads [request performRequestWithHandler: ]; Request Handler Block This handler is

    not guaranteed to be called on any particular thread. Apple Monday, May 7, 12
  46. Danger ^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { // Parse

    the Twitter response. ... // Assign an array of tweets to our tweets property. ... // Reload the table view. // This might not work! [self.tableView reloadData]; } Request Handler Block Monday, May 7, 12
  47. OK ^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { // Parse

    the Twitter response. ... // Assign an array of tweets to our tweets property. ... // Reload the table view. This will work! [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; } Request Handler Block Monday, May 7, 12
  48. JSON { "completed_in": 0.108, "page": 1, "results_per_page": 100, "query": "%23mobilemarch+OR+%40mobilemarchtc",

    ... "results": [ { "created_at": "Thu, 15 Mar 2012 16:41:16 +0000", "from_user": "teruterubouzu", "text": "@mobilemarchtc How late ...", ... }, { "created_at": "Thu, 15 Mar 2012 14:20:49 +0000", "from_user": "billyspringer", "text": "RT @smbmsp: RT @philson: ...", ... Twitter Request GET http://search.twitter.com/search.json Twitter Response Monday, May 7, 12
  49. Twitter Response NSData [NSJSONSerialization JSONObjectWithData: options:0 error:&error]; Twitter Response NSData

    Twitter Response NSDictionary Monday, May 7, 12
  50. Demo Monday, May 7, 12

  51. Next Steps •Start your own app! •Apple’s Getting Started Guide

    •Apple’s Sample Code •WWDC Videos Monday, May 7, 12
  52. #prowess Sam Kirchmeier, Livefront @skirchmeier Bob McCune, TapHarmonic @bobmccune Monday,

    May 7, 12