Irving iOS Jumpstart Meetup - Objective-C Session 2

639 views

Published on

Session 2 of Objective-C for the Irving iOS Jumpstart meetup. This evening we learned about creating UITableView's and programmatically setting the contents of their UITableViewCell's.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
639
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Irving iOS Jumpstart Meetup - Objective-C Session 2

  1. 1. Objective-C Programming Irving iOS Jumpstart
  2. 2. Objective-C Programming March 11, 2014
  3. 3. Overview of Today • Quick 5 Realms Overview • Objective-C Messaging • Simple Programmatic UITableView Example • Realistic UITableView Example
  4. 4. 5 Realms for Learning iOS Development Download full 5 Realms presentation at: http://www.slideshare.net/irving-ios-jumpstart/5-realms
  5. 5. Why 5 Realms? To the beginning iOS developer the formalities of classes, frameworks, design patterns, and learning an all new integrated development environment can be overwhelming.
  6. 6. Why 5 Realms? Knowing which realm you're having trouble in really helps in finding the solution and getting unstuck in your learning efforts.
  7. 7. 5 Realms Design Patterns Objective-C iOS SDK OOP Xcode IDE
  8. 8. Objective-C Messaging Objective-C
  9. 9. Defining Classes in Objective-C • Created via .h file and .m file • All classes inherit from NSObject or another class Objective-C
  10. 10. @interface @implementation • @interface in an objective-c .h file • @implementation in an objective-c .m file • serves to separate the interface of a class from its implementation. Objective-C
  11. 11. @property @synthesize • Objective-C properties • @property directive is used to create properties on the class. • Properties are accessed (read and set) via automagically created setters and getters. • In Xcode 5, optionally use @synthesize to give instance variable a custom name Objective-C
  12. 12. Objective-C Methods • Class method + (return_type)methodName • Instance method - (return_type)methodName • Distinguished by + or - Objective-C
  13. 13. Objective-C Methods - (void)addHotels { NSArray *hotels = [NSArray arrayWithObjects:@"Aloft", @"The W", @"Hilton", nil]; ourHotels = [NSArray arrayWithArray:hotels]; } - (return_type)methodName Objective-C
  14. 14. Method With Arguments • this method has one argument - (void)listOurHotelsUsingTitle: (NSString *)title { NSLog(@"%@: %@", title, ourHotels); } Objective-C
  15. 15. Method With Arguments • including sample method call below - (void)listOurHotelsUsingTitle:(NSString *)title { NSLog(@"%@: %@", title, ourHotels); } ! [self listOurHotelsUsingTitle:@"Favorite Hotels"]; Objective-C
  16. 16. Foundation Framework • NSString - the Foundation Framework class used to create string objects! NSString *city = @"Irving"; iOS SDK
  17. 17. Foundation Framework NSString *myStory = [NSString stringWithFormat:@"The brown fox lives in %@", city]; //The brown fox lives in Irving iOS SDK
  18. 18. Foundation Framework • NSString comparison if ([city isEqualToString:@"Irving"]) { NSLog(@"The two strings are the same."); } else { NSLog(@"The two strings are different."); } //The two strings are the same. iOS SDK
  19. 19. Foundation Framework • NSString comparison if ([city isEqualToString:myStory]) { NSLog(@"The two strings are the same."); } else { NSLog(@"The two strings are different."); } //The two strings are different. iOS SDK
  20. 20. Foundation Framework • NSArray - the Foundation Framework class used to create array objects! NSArray *hotels = [NSArray arrayWithObjects:@"Aloft", @"The W", @"Hilton", nil]; • An array is a set of ordered data items iOS SDK
  21. 21. Foundation Framework NSArray *hotels = [NSArray arrayWithObjects:@"Aloft", @"The W", @"Hilton", nil]; • array index begins at zero, so an array with 3 elements are indexed 0, 1, and 2 NSLog(@"The hotel at index 1 in this array is %@", [hotels objectAtIndex:1]); // The W iOS SDK
  22. 22. Foundation Framework • NSArray shortcut (objective-c literals)! NSArray *hotels = @[@"Aloft", @"The W", @"Hilton"]; • Cleaner and familiar syntax iOS SDK
  23. 23. Foundation Framework • NSDictionary - the Foundation Framework class used to store key and value pairs! NSDictionary *hotels = [NSDictionary dictionaryWithObjectsAndKeys:@"5 star", @"Aloft", @"4 star", @"W", @"5 star", @"Hilton", nil]; iOS SDK
  24. 24. Foundation Framework - (void)addHotelsWithRatings { NSDictionary *hotels = [NSDictionary dictionaryWithObjectsAndKeys:@"5 star", @"Aloft", @"4 star", @"W", @"5 star", @"Hilton", nil]; ! NSLog(@"%@", hotels); } iOS SDK
  25. 25. Foundation Framework • NSDictionary shortcut (objective-c literals)! NSDictionary *hotels = @{@"Aloft":@"5 star", @"W":@"4 star", @"Hilton":@"5 star"}; • Cleaner syntax iOS SDK
  26. 26. Foundation Framework • Mutable objects are changeable after creation. • Immutable objects cannot change once they are created. • Therefore additional methods exist on mutable objects iOS SDK
  27. 27. Mutable Objects NSString (immutable) NSMutableString (mutable) NSArray NSMutableArray NSDictionary NSMutableDictionary iOS SDK
  28. 28. Mutable Objects • NSMutableString Example NSMutableString *iCanChange = [NSMutableString stringWithString:@"Hello..."]; NSLog(@"%@", [iCanChange stringByAppendingString:@"world!"]); // Hello...world! iOS SDK
  29. 29. Mutable Objects Download samples from github ! https://github.com/jamesderry iOS SDK
  30. 30. Programmatic UITableView Crosses several realms of IOS understanding. ! ! ! Design Patterns Objective-C iOS SDK OOP Xcode IDE
  31. 31. Programmatic UITableView • Xcode • Storyboard - we'll build the view controller storyboard containing a tableview • IBOutlet - we'll use to grab a handle to the tableview for manipulation in objective-c code Xcode IDE
  32. 32. Programmatic UITableView • Design Patterns • Model - View - Controller (MVC) pattern • Delegate pattern • Datasource pattern Design Patterns
  33. 33. Programmatic UITableView • Objective-C features • Protocols • Classes (UITableView and UITableViewCell) • Dot syntax for cell properties Objective-C
  34. 34. Programmatic UITableView • iOS SDK Features • UIViewController (and view controller life cycle) • UIView • UITableView and UITableViewCell iOS SDK
  35. 35. Programmatic UITableView Exercise Create simple table view app
  36. 36. Programmatic UITableView Exercise Common Pitfalls • forgetting to match the prototype cell identifier name to the name used in your code • forgetting to set the tableview datasource and delegate
  37. 37. Thank You! • Credits • Wikipedia • Programming in Objective-C by Stephen Kochan (any errors or omissions are probably mine)

×