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. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. ^(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
  9. Threads [request performRequestWithHandler: ]; Request Handler Block This handler is

    not guaranteed to be called on any particular thread. Apple Monday, May 7, 12
  10. 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
  11. 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
  12. 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
  13. Next Steps •Start your own app! •Apple’s Getting Started Guide

    •Apple’s Sample Code •WWDC Videos Monday, May 7, 12