Slide 1

Slide 1 text

iOS Training Part 2 Sam Kirchmeier [email protected] @skirchmeier Monday, May 7, 12

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

Topics •Storyboards •Navigation Controllers •Table View Controllers Monday, May 7, 12

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

Storyboards Monday, May 7, 12

Slide 7

Slide 7 text

Scenes View Controllers Segues Transitions Monday, May 7, 12

Slide 8

Slide 8 text

Monday, May 7, 12

Slide 9

Slide 9 text

Scene Monday, May 7, 12

Slide 10

Slide 10 text

Scene Segue Monday, May 7, 12

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

Demo Monday, May 7, 12

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Navigation Controller Monday, May 7, 12

Slide 15

Slide 15 text

Monday, May 7, 12

Slide 16

Slide 16 text

Monday, May 7, 12

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

Demo Monday, May 7, 12

Slide 19

Slide 19 text

Table View Controller Monday, May 7, 12

Slide 20

Slide 20 text

Monday, May 7, 12

Slide 21

Slide 21 text

Monday, May 7, 12

Slide 22

Slide 22 text

Navigation Controller Monday, May 7, 12

Slide 23

Slide 23 text

Navigation Controller View Controller Monday, May 7, 12

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

Navigation Controller View Controller Table View Delegate Data Source Monday, May 7, 12

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

Navigation Controller Table View Controller Table View Built In Data Source Delegate Monday, May 7, 12

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

UITableViewDelegate – tableView:didSelectRowAtIndexPath: – tableView:heightForRowAtIndexPath: – tableView:viewForHeaderInSection: – tableView:viewForFooterInSection: (and lots more) Monday, May 7, 12

Slide 35

Slide 35 text

UITableViewCell Monday, May 7, 12

Slide 36

Slide 36 text

Basic Monday, May 7, 12

Slide 37

Slide 37 text

Right Detail Monday, May 7, 12

Slide 38

Slide 38 text

Left Detail Monday, May 7, 12

Slide 39

Slide 39 text

Subtitle Monday, May 7, 12

Slide 40

Slide 40 text

Demo Monday, May 7, 12

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

Twitter Framework Monday, May 7, 12

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

^(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

Slide 45

Slide 45 text

Threads [request performRequestWithHandler: ]; Request Handler Block This handler is not guaranteed to be called on any particular thread. Apple Monday, May 7, 12

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

Twitter Response NSData [NSJSONSerialization JSONObjectWithData: options:0 error:&error]; Twitter Response NSData Twitter Response NSDictionary Monday, May 7, 12

Slide 50

Slide 50 text

Demo Monday, May 7, 12

Slide 51

Slide 51 text

Next Steps •Start your own app! •Apple’s Getting Started Guide •Apple’s Sample Code •WWDC Videos Monday, May 7, 12

Slide 52

Slide 52 text

#prowess Sam Kirchmeier, Livefront @skirchmeier Bob McCune, TapHarmonic @bobmccune Monday, May 7, 12