08 table views
DESCRIPTION
TRANSCRIPT
![Page 1: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/1.jpg)
CS193P - Lecture 8iPhone Application Development
Scroll Views & Table Views
1Saturday, January 30, 2010
![Page 2: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/2.jpg)
2Saturday, January 30, 2010
![Page 3: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/3.jpg)
iPhone SDK 3.2
3Saturday, January 30, 2010
![Page 4: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/4.jpg)
iPhone SDK 3.2• Support for iPad
3Saturday, January 30, 2010
![Page 5: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/5.jpg)
iPhone SDK 3.2• Support for iPad• Beta Release
3Saturday, January 30, 2010
![Page 6: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/6.jpg)
iPhone SDK 3.2• Support for iPad• Beta Release
Enrollment in iPhone Developer Standard or Enterprise required
3Saturday, January 30, 2010
![Page 7: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/7.jpg)
Announcements• Paparazzi 1 due next Wednesday (2/3)
4Saturday, January 30, 2010
![Page 8: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/8.jpg)
Today’s Topics• Scroll views• Table views
■ Displaying data■ Controlling appearance & behavior
• UITableViewController• Table view cells
5Saturday, January 30, 2010
![Page 9: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/9.jpg)
Scroll Views
6Saturday, January 30, 2010
![Page 10: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/10.jpg)
UIScrollView• For displaying more content than can fit on the screen
7Saturday, January 30, 2010
![Page 11: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/11.jpg)
UIScrollView• For displaying more content than can fit on the screen• Handles gestures for panning and zooming
7Saturday, January 30, 2010
![Page 12: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/12.jpg)
UIScrollView• For displaying more content than can fit on the screen• Handles gestures for panning and zooming• Noteworthy subclasses: UITableView and UITextView
7Saturday, January 30, 2010
![Page 13: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/13.jpg)
Scrolling Examples
8Saturday, January 30, 2010
![Page 14: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/14.jpg)
Scrolling Examples
8Saturday, January 30, 2010
![Page 15: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/15.jpg)
Scrolling Examples
8Saturday, January 30, 2010
![Page 16: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/16.jpg)
Scrolling Examples
8Saturday, January 30, 2010
![Page 17: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/17.jpg)
Scrolling Examples
8Saturday, January 30, 2010
![Page 18: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/18.jpg)
Scrolling Examples
8Saturday, January 30, 2010
![Page 19: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/19.jpg)
Content Size
9Saturday, January 30, 2010
![Page 20: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/20.jpg)
Content Size
contentSize.height
contentSize.width
9Saturday, January 30, 2010
![Page 21: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/21.jpg)
Content Inset
contentSize.height
contentSize.width
contentInset.top
contentInset.bottom
10Saturday, January 30, 2010
![Page 22: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/22.jpg)
Content Inset
11Saturday, January 30, 2010
![Page 23: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/23.jpg)
Content Inset
11Saturday, January 30, 2010
![Page 24: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/24.jpg)
Content Inset
12Saturday, January 30, 2010
![Page 25: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/25.jpg)
Content Inset
contentInset.top
12Saturday, January 30, 2010
![Page 26: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/26.jpg)
Content Inset
contentInset.top
13Saturday, January 30, 2010
![Page 27: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/27.jpg)
Content Inset
contentInset.bottom
contentInset.top
13Saturday, January 30, 2010
![Page 28: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/28.jpg)
Scroll Indicator Insets
14Saturday, January 30, 2010
![Page 29: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/29.jpg)
Scroll Indicator Insets
14Saturday, January 30, 2010
![Page 30: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/30.jpg)
Scroll Indicator Insets
14Saturday, January 30, 2010
![Page 31: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/31.jpg)
scrollIndicatorInsets.top
Scroll Indicator Insets
14Saturday, January 30, 2010
![Page 32: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/32.jpg)
ContentOffset
15Saturday, January 30, 2010
![Page 33: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/33.jpg)
ContentOffset
15Saturday, January 30, 2010
![Page 34: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/34.jpg)
ContentOffset
15Saturday, January 30, 2010
![Page 35: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/35.jpg)
contentSize.height
contentSize.width
contentInset.top
contentInset.bottom
contentInset.left contentInset.right
16Saturday, January 30, 2010
![Page 36: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/36.jpg)
17Saturday, January 30, 2010
![Page 37: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/37.jpg)
contentOffset.y
contentOffset.x
17Saturday, January 30, 2010
![Page 38: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/38.jpg)
18Saturday, January 30, 2010
![Page 39: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/39.jpg)
18Saturday, January 30, 2010
![Page 40: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/40.jpg)
contentOffset.y(-contentInset.top)
contentOffset.x(-contentInset.left)
18Saturday, January 30, 2010
![Page 41: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/41.jpg)
Using a Scroll View
19Saturday, January 30, 2010
![Page 42: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/42.jpg)
Using a Scroll View• Create with the desired frame
CGRect frame = CGRectMake(0, 0, 200, 200);scrollView = [[UIScrollView alloc] initWithFrame:frame];
19Saturday, January 30, 2010
![Page 43: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/43.jpg)
Using a Scroll View• Create with the desired frame
• Add subviews (frames may extend beyond scroll view bounds)
CGRect frame = CGRectMake(0, 0, 200, 200);scrollView = [[UIScrollView alloc] initWithFrame:frame];
frame = CGRectMake(0, 0, 500, 500);myImageView = [[UIImageView alloc] initWithFrame:frame];[scrollView addSubview:myImageView];
19Saturday, January 30, 2010
![Page 44: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/44.jpg)
Using a Scroll View• Create with the desired frame
• Add subviews (frames may extend beyond scroll view bounds)
• Set the content sizescrollView.contentSize = CGSizeMake(500, 500);
CGRect frame = CGRectMake(0, 0, 200, 200);scrollView = [[UIScrollView alloc] initWithFrame:frame];
frame = CGRectMake(0, 0, 500, 500);myImageView = [[UIImageView alloc] initWithFrame:frame];[scrollView addSubview:myImageView];
19Saturday, January 30, 2010
![Page 45: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/45.jpg)
Extending Scroll View Behavior• Applications often want to know about scroll events
20Saturday, January 30, 2010
![Page 46: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/46.jpg)
Extending Scroll View Behavior• Applications often want to know about scroll events
■ When the scroll offset is changed
20Saturday, January 30, 2010
![Page 47: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/47.jpg)
Extending Scroll View Behavior• Applications often want to know about scroll events
■ When the scroll offset is changed■ When dragging begins & ends
20Saturday, January 30, 2010
![Page 48: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/48.jpg)
Extending Scroll View Behavior• Applications often want to know about scroll events
■ When the scroll offset is changed■ When dragging begins & ends■ When deceleration begins & ends
20Saturday, January 30, 2010
![Page 49: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/49.jpg)
Extending with a Subclass• Create a subclass• Override methods to customize behavior
21Saturday, January 30, 2010
![Page 50: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/50.jpg)
Extending with a Subclass• Create a subclass• Override methods to customize behavior
• Issues with this approach
21Saturday, January 30, 2010
![Page 51: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/51.jpg)
Extending with a Subclass• Create a subclass• Override methods to customize behavior
• Issues with this approach■ Application logic and behavior is now part of a View class
21Saturday, January 30, 2010
![Page 52: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/52.jpg)
Extending with a Subclass• Create a subclass• Override methods to customize behavior
• Issues with this approach■ Application logic and behavior is now part of a View class■ Tedious to write a one-off subclass for every scroll view instance
21Saturday, January 30, 2010
![Page 53: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/53.jpg)
Extending with a Subclass• Create a subclass• Override methods to customize behavior
• Issues with this approach■ Application logic and behavior is now part of a View class■ Tedious to write a one-off subclass for every scroll view instance■ Your code becomes tightly coupled with superclass
21Saturday, January 30, 2010
![Page 54: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/54.jpg)
Extending with Delegation• Delegate is a separate object• Clearly defined points of responsibility
■ Change behavior■ Customize appearance
• Loosely coupled with the object being extended
22Saturday, January 30, 2010
![Page 55: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/55.jpg)
UIScrollView Delegate
23Saturday, January 30, 2010
![Page 56: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/56.jpg)
UIScrollView Delegate
@protocol UIScrollViewDelegate<NSObject>
23Saturday, January 30, 2010
![Page 57: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/57.jpg)
UIScrollView Delegate
@protocol UIScrollViewDelegate<NSObject>
@optional
23Saturday, January 30, 2010
![Page 58: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/58.jpg)
UIScrollView Delegate
@protocol UIScrollViewDelegate<NSObject>
@optional
// Respond to interesting events- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
23Saturday, January 30, 2010
![Page 59: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/59.jpg)
UIScrollView Delegate
@protocol UIScrollViewDelegate<NSObject>
@optional
// Respond to interesting events- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
...
// Influence behavior- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView;
@end
23Saturday, January 30, 2010
![Page 60: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/60.jpg)
Implementing a Delegate
24Saturday, January 30, 2010
![Page 61: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/61.jpg)
Implementing a Delegate• Conform to the delegate protocol
@interface MyController : NSObject <UIScrollViewDelegate>
24Saturday, January 30, 2010
![Page 62: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/62.jpg)
Implementing a Delegate• Conform to the delegate protocol
• Implement all required methods and any optional methods
@interface MyController : NSObject <UIScrollViewDelegate>
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
// Do something in response to the new scroll positionif (scrollView.contentOffset ...) {
}}
24Saturday, January 30, 2010
![Page 63: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/63.jpg)
Zooming with a Scroll View
25Saturday, January 30, 2010
![Page 64: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/64.jpg)
Zooming with a Scroll View• Set the minimum, maximum, initial zoom scalesscrollView.maximumZoomScale = 2.0;scrollView.minimumZoomScale = scrollView.size.width / myImage.size.width;
25Saturday, January 30, 2010
![Page 65: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/65.jpg)
Zooming with a Scroll View• Set the minimum, maximum, initial zoom scales
• Implement delegate method for zooming
scrollView.maximumZoomScale = 2.0;scrollView.minimumZoomScale = scrollView.size.width / myImage.size.width;
- (UIView *)viewForZoomingInScrollView:(UIView *)view{
return someViewThatWillBeScaled;}
25Saturday, January 30, 2010
![Page 66: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/66.jpg)
- (void)setZoomScale:(float)scale animated:(BOOL);
Set Zoom Scale
26Saturday, January 30, 2010
![Page 67: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/67.jpg)
- (void)setZoomScale:(float)scale animated:(BOOL);
Set Zoom Scale
26Saturday, January 30, 2010
![Page 68: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/68.jpg)
- (void)setZoomScale:(float)scale animated:(BOOL);
Set Zoom Scale
26Saturday, January 30, 2010
![Page 69: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/69.jpg)
- (void)zoomToRect:(CGRect)rect animated:(BOOL);
Zoom to Rect
27Saturday, January 30, 2010
![Page 70: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/70.jpg)
- (void)zoomToRect:(CGRect)rect animated:(BOOL);
Zoom to Rect
27Saturday, January 30, 2010
![Page 71: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/71.jpg)
- (void)zoomToRect:(CGRect)rect animated:(BOOL);
Zoom to Rect
27Saturday, January 30, 2010
![Page 72: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/72.jpg)
- (void)zoomToRect:(CGRect)rect animated:(BOOL);
Zoom to Rect
28Saturday, January 30, 2010
![Page 73: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/73.jpg)
- (void)zoomToRect:(CGRect)rect animated:(BOOL);
Zoom to Rect
28Saturday, January 30, 2010
![Page 74: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/74.jpg)
- (void)zoomToRect:(CGRect)rect animated:(BOOL);
Zoom to Rect
28Saturday, January 30, 2010
![Page 75: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/75.jpg)
Demo
29Saturday, January 30, 2010
![Page 76: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/76.jpg)
Table Views
30Saturday, January 30, 2010
![Page 77: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/77.jpg)
Table Views• Display lists of content
■ Single column, multiple rows ■ Vertical scrolling■ Large data sets
• Powerful and ubiquitous in iPhone applications
31Saturday, January 30, 2010
![Page 78: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/78.jpg)
Table View Styles
32Saturday, January 30, 2010
![Page 79: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/79.jpg)
Table View Styles
UITableViewStylePlain
32Saturday, January 30, 2010
![Page 80: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/80.jpg)
Table View Styles
UITableViewStylePlain UITableViewStyleGrouped
32Saturday, January 30, 2010
![Page 81: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/81.jpg)
Table View AnatomyPlain Style
33Saturday, January 30, 2010
![Page 82: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/82.jpg)
Table Header
Table View AnatomyPlain Style
33Saturday, January 30, 2010
![Page 83: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/83.jpg)
Table Footer
Table Header
Table View AnatomyPlain Style
33Saturday, January 30, 2010
![Page 84: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/84.jpg)
Table Footer
Table Header
Section
Table View AnatomyPlain Style
33Saturday, January 30, 2010
![Page 85: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/85.jpg)
Table Footer
Table HeaderSection Header
Section
Table View AnatomyPlain Style
33Saturday, January 30, 2010
![Page 86: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/86.jpg)
Table Footer
Table HeaderSection Header
Section Footer
Section
Table View AnatomyPlain Style
33Saturday, January 30, 2010
![Page 87: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/87.jpg)
Table Cell
Table Footer
Table HeaderSection Header
Section Footer
Section
Table View AnatomyPlain Style
33Saturday, January 30, 2010
![Page 88: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/88.jpg)
Table Cell
Table Footer
Table HeaderSection Header
Section Footer
Section
Table View AnatomyPlain Style
34Saturday, January 30, 2010
![Page 89: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/89.jpg)
Table Cell
Table Footer
Table Header
Section Header
Section Footer
Section
Table View AnatomyGrouped Style
35Saturday, January 30, 2010
![Page 90: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/90.jpg)
Using Table Views• Displaying your data in the table view• Customizing appearance & behavior
36Saturday, January 30, 2010
![Page 91: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/91.jpg)
Displaying Data in a Table View
37Saturday, January 30, 2010
![Page 92: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/92.jpg)
A Naïve Solution
38Saturday, January 30, 2010
![Page 93: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/93.jpg)
A Naïve Solution• Table views display a list of data, so use an array
[myTableView setList:myListOfStuff];
38Saturday, January 30, 2010
![Page 94: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/94.jpg)
A Naïve Solution• Table views display a list of data, so use an array
[myTableView setList:myListOfStuff];
• Issues with this approach
38Saturday, January 30, 2010
![Page 95: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/95.jpg)
A Naïve Solution• Table views display a list of data, so use an array
[myTableView setList:myListOfStuff];
• Issues with this approach■ All data is loaded upfront
38Saturday, January 30, 2010
![Page 96: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/96.jpg)
A Naïve Solution• Table views display a list of data, so use an array
[myTableView setList:myListOfStuff];
• Issues with this approach■ All data is loaded upfront■ All data stays in memory
38Saturday, January 30, 2010
![Page 97: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/97.jpg)
A More Flexible Solution• Another object provides data to the table view
■ Not all at once■ Just as it’s needed for display
• Like a delegate, but purely data-oriented
39Saturday, January 30, 2010
![Page 98: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/98.jpg)
UITableViewDataSource
40Saturday, January 30, 2010
![Page 99: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/99.jpg)
UITableViewDataSource• Provide number of sections and rows// Optional method, defaults to 1 if not implemented- (NSInteger)numberOfSectionsInTableView:(UITableView *)table;
// Required method- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
40Saturday, January 30, 2010
![Page 100: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/100.jpg)
UITableViewDataSource• Provide number of sections and rows
• Provide cells for table view as needed
// Optional method, defaults to 1 if not implemented- (NSInteger)numberOfSectionsInTableView:(UITableView *)table;
// Required method- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
// Required method- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
40Saturday, January 30, 2010
![Page 101: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/101.jpg)
Datasource Message Flow
Datasource
41Saturday, January 30, 2010
![Page 102: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/102.jpg)
Datasource Message Flow
Datasource
How many sections?
numberOfSectionsInTableView:
41Saturday, January 30, 2010
![Page 103: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/103.jpg)
Datasource Message Flow
Datasource
numberOfSectionsInTableView:
5
41Saturday, January 30, 2010
![Page 104: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/104.jpg)
Datasource Message Flow
Datasource
42Saturday, January 30, 2010
![Page 105: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/105.jpg)
Datasource Message Flow
Datasource
tableView:numberOfRowsInSection:
How many rows in section 0?
42Saturday, January 30, 2010
![Page 106: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/106.jpg)
Datasource Message Flow
Datasource
tableView:numberOfRowsInSection:
1
42Saturday, January 30, 2010
![Page 107: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/107.jpg)
Datasource Message Flow
Datasource
43Saturday, January 30, 2010
![Page 108: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/108.jpg)
Datasource Message Flow
Datasource
tableView:cellForRowAtIndexPath:
What to display at section 0, row 0?
43Saturday, January 30, 2010
![Page 109: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/109.jpg)
Datasource Message Flow
Datasource
tableView:cellForRowAtIndexPath:
Cell with text “John Appleseed”
43Saturday, January 30, 2010
![Page 110: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/110.jpg)
NSIndexPath• Generic class in Foundation• Path to a specific node in a tree of nested arrays
0
1
2
3
4
44Saturday, January 30, 2010
![Page 111: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/111.jpg)
NSIndexPath• Generic class in Foundation• Path to a specific node in a tree of nested arrays
0
1
2
3
4
0
1
2
3
4
0
1
2
3
4
0
1
2
3
4
44Saturday, January 30, 2010
![Page 112: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/112.jpg)
NSIndexPath and Table Views• Cell location described with an index path
■ Section index + row index
45Saturday, January 30, 2010
![Page 113: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/113.jpg)
NSIndexPath and Table Views• Cell location described with an index path
■ Section index + row index
• Category on NSIndexPath with helper methods
@interface NSIndexPath (UITableView)
+ (NSIndexPath *)indexPathForRow:(NSUInteger)row inSection:(NSUInteger)section;
@property(nonatomic,readonly) NSUInteger section;@property(nonatomic,readonly) NSUInteger row;
@end
45Saturday, January 30, 2010
![Page 114: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/114.jpg)
Single Section Table View
46Saturday, January 30, 2010
![Page 115: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/115.jpg)
Single Section Table View• Return the number of rows- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [myStrings count];}
46Saturday, January 30, 2010
![Page 116: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/116.jpg)
Single Section Table View• Return the number of rows
• Provide a cell when requested
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = ...;cell.textLabel.text = [myStrings objectAtIndex:indexPath.row]return [cell autorelease];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [myStrings count];}
46Saturday, January 30, 2010
![Page 117: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/117.jpg)
Cell Reuse
47Saturday, January 30, 2010
![Page 118: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/118.jpg)
Cell Reuse• When asked for a cell, it would be expensive to create a new
cell each time.
47Saturday, January 30, 2010
![Page 119: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/119.jpg)
Cell Reuse• When asked for a cell, it would be expensive to create a new
cell each time.
- (UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier;
47Saturday, January 30, 2010
![Page 120: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/120.jpg)
Cell Reuse• When asked for a cell, it would be expensive to create a new
cell each time.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@“MyIdentifier”];
if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:... reuseIdentifier:@“MyIdenifier”] autorelease];}
cell.text = [myStrings objectAtIndex:indexPath.row]
return cell;}
47Saturday, January 30, 2010
![Page 121: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/121.jpg)
Triggering Updates• When is the datasource asked for its data?
48Saturday, January 30, 2010
![Page 122: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/122.jpg)
Triggering Updates• When is the datasource asked for its data?
■ When a row becomes visible
48Saturday, January 30, 2010
![Page 123: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/123.jpg)
Triggering Updates• When is the datasource asked for its data?
■ When a row becomes visible■ When an update is explicitly requested by calling -reloadData
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.tableView reloadData];}
48Saturday, January 30, 2010
![Page 124: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/124.jpg)
Section and Row Reloading
49Saturday, January 30, 2010
![Page 125: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/125.jpg)
Section and Row Reloading- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
49Saturday, January 30, 2010
![Page 126: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/126.jpg)
Section and Row Reloading
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
49Saturday, January 30, 2010
![Page 127: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/127.jpg)
Section and Row Reloading
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
49Saturday, January 30, 2010
![Page 128: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/128.jpg)
Section and Row Reloading
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
49Saturday, January 30, 2010
![Page 129: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/129.jpg)
Section and Row Reloading
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
49Saturday, January 30, 2010
![Page 130: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/130.jpg)
Section and Row Reloading
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
49Saturday, January 30, 2010
![Page 131: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/131.jpg)
Additional Datasource Methods• Titles for section headers and footers• Allow editing and reordering cells
50Saturday, January 30, 2010
![Page 132: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/132.jpg)
Appearance & Behavior
51Saturday, January 30, 2010
![Page 133: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/133.jpg)
UITableView Delegate• Customize appearance and behavior• Keep application logic separate from view
• Often the same object as datasource
52Saturday, January 30, 2010
![Page 134: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/134.jpg)
Table View Appearance & Behavior
53Saturday, January 30, 2010
![Page 135: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/135.jpg)
Table View Appearance & Behavior• Customize appearance of table view cell
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cellforRowAtIndexPath:(NSIndexPath *)indexPath;
53Saturday, January 30, 2010
![Page 136: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/136.jpg)
Table View Appearance & Behavior• Customize appearance of table view cell
• Validate and respond to selection changes
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cellforRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSIndexPath *)tableView:(UITableView *)tableViewwillSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath;
53Saturday, January 30, 2010
![Page 137: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/137.jpg)
Row Selection in Table Views• In iPhone applications, rows rarely stay selected• Selecting a row usually triggers an event
54Saturday, January 30, 2010
![Page 138: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/138.jpg)
Row Selection in Table Views• In iPhone applications, rows rarely stay selected• Selecting a row usually triggers an event
54Saturday, January 30, 2010
![Page 139: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/139.jpg)
Persistent Selection
55Saturday, January 30, 2010
![Page 140: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/140.jpg)
Persistent Selection
55Saturday, January 30, 2010
![Page 141: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/141.jpg)
Responding to Selection// For a navigation hierarchy...- (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{
56Saturday, January 30, 2010
![Page 142: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/142.jpg)
Responding to Selection// For a navigation hierarchy...- (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// Get the row and the object it represents
56Saturday, January 30, 2010
![Page 143: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/143.jpg)
Responding to Selection// For a navigation hierarchy...- (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// Get the row and the object it representsNSUInteger row = indexPath.row
56Saturday, January 30, 2010
![Page 144: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/144.jpg)
Responding to Selection// For a navigation hierarchy...- (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// Get the row and the object it representsNSUInteger row = indexPath.rowid objectToDisplay = [myObjects objectAtIndex:row];
56Saturday, January 30, 2010
![Page 145: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/145.jpg)
Responding to Selection// For a navigation hierarchy...- (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// Get the row and the object it representsNSUInteger row = indexPath.rowid objectToDisplay = [myObjects objectAtIndex:row];
// Create a new view controller and pass it along
56Saturday, January 30, 2010
![Page 146: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/146.jpg)
Responding to Selection// For a navigation hierarchy...- (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// Get the row and the object it representsNSUInteger row = indexPath.rowid objectToDisplay = [myObjects objectAtIndex:row];
// Create a new view controller and pass it alongMyViewController *myViewController = ...;
56Saturday, January 30, 2010
![Page 147: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/147.jpg)
Responding to Selection// For a navigation hierarchy...- (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// Get the row and the object it representsNSUInteger row = indexPath.rowid objectToDisplay = [myObjects objectAtIndex:row];
// Create a new view controller and pass it alongMyViewController *myViewController = ...;myViewController.object = objectToDisplay;
56Saturday, January 30, 2010
![Page 148: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/148.jpg)
Responding to Selection// For a navigation hierarchy...- (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// Get the row and the object it representsNSUInteger row = indexPath.rowid objectToDisplay = [myObjects objectAtIndex:row];
// Create a new view controller and pass it alongMyViewController *myViewController = ...;myViewController.object = objectToDisplay;
[self.navigationController pushViewController:myViewController animated:YES];
}
56Saturday, January 30, 2010
![Page 149: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/149.jpg)
Altering or Disabling Selection- (NSIndexPath *)tableView:(UITableView *)tableViewwillSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// Don’t allow selecting certain rows?if (indexPath.row == ...) {
return nil;} else {
return indexPath;}
}
57Saturday, January 30, 2010
![Page 150: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/150.jpg)
UITableViewController
58Saturday, January 30, 2010
![Page 151: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/151.jpg)
UITableViewController
59Saturday, January 30, 2010
![Page 152: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/152.jpg)
UITableViewController• Convenient starting point for view controller with a table view
■ Table view is automatically created■ Controller is table view’s delegate and datasource
59Saturday, January 30, 2010
![Page 153: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/153.jpg)
UITableViewController• Convenient starting point for view controller with a table view
■ Table view is automatically created■ Controller is table view’s delegate and datasource
• Takes care of some default behaviors■ Calls -reloadData the first time it appears■ Deselects rows when user navigates back■ Flashes scroll indicators
59Saturday, January 30, 2010
![Page 154: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/154.jpg)
Table View Cells
60Saturday, January 30, 2010
![Page 155: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/155.jpg)
Designated Initializer
61Saturday, January 30, 2010
![Page 156: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/156.jpg)
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier;
Designated Initializer
61Saturday, January 30, 2010
![Page 157: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/157.jpg)
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier;
Designated Initializer
DEPRECATED
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier;
61Saturday, January 30, 2010
![Page 158: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/158.jpg)
Cell Styles
62Saturday, January 30, 2010
![Page 159: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/159.jpg)
Cell Styles
UITableViewCellStyleDefault
62Saturday, January 30, 2010
![Page 160: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/160.jpg)
Cell Styles
UITableViewCellStyleDefault
UITableViewCellStyleSubtitle
62Saturday, January 30, 2010
![Page 161: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/161.jpg)
Cell Styles
UITableViewCellStyleDefault
UITableViewCellStyleSubtitle
UITableViewCellStyleValue1
62Saturday, January 30, 2010
![Page 162: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/162.jpg)
Cell Styles
UITableViewCellStyleDefault
UITableViewCellStyleSubtitle
UITableViewCellStyleValue1
UITableViewCellStyleValue2
62Saturday, January 30, 2010
![Page 163: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/163.jpg)
Basic properties• UITableViewCell has an image view and one or two text labels
63Saturday, January 30, 2010
![Page 164: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/164.jpg)
Basic properties• UITableViewCell has an image view and one or two text labels
cell.imageView.image = [UIImage imageNamed:@“vitolidol.png”];cell.textLabel.text = @“Vitol Idol”;cell.detailTextLabel.text = @“Billy Idol”;
63Saturday, January 30, 2010
![Page 165: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/165.jpg)
Accessory Types// UITableView delegate method- (UITableViewCellAccessoryType)tableView:(UITableView *)table accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath;
64Saturday, January 30, 2010
![Page 166: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/166.jpg)
Accessory Types// UITableView delegate method- (UITableViewCellAccessoryType)tableView:(UITableView *)table accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath;
UITableViewCellAccessoryDisclosureIndicator
64Saturday, January 30, 2010
![Page 167: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/167.jpg)
Accessory Types// UITableView delegate method- (UITableViewCellAccessoryType)tableView:(UITableView *)table accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath;
UITableViewCellAccessoryDisclosureIndicator
UITableViewCellAccessoryDetailDisclosureButton
64Saturday, January 30, 2010
![Page 168: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/168.jpg)
Accessory Types
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
// Only for the blue disclosure buttonNSUInteger row = indexPath.row;...
}
// UITableView delegate method- (UITableViewCellAccessoryType)tableView:(UITableView *)table accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath;
UITableViewCellAccessoryDisclosureIndicator
UITableViewCellAccessoryDetailDisclosureButton
64Saturday, January 30, 2010
![Page 169: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/169.jpg)
Accessory Types
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
// Only for the blue disclosure buttonNSUInteger row = indexPath.row;...
}
// UITableView delegate method- (UITableViewCellAccessoryType)tableView:(UITableView *)table accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath;
UITableViewCellAccessoryDisclosureIndicator
UITableViewCellAccessoryDetailDisclosureButton
UITableViewCellAccessoryCheckmark
64Saturday, January 30, 2010
![Page 170: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/170.jpg)
Customizing the Content View• For cases where a simple image + text cell doesn’t suffice• UITableViewCell has a content view property
■ Add additional views to the content view
65Saturday, January 30, 2010
![Page 171: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/171.jpg)
Customizing the Content View• For cases where a simple image + text cell doesn’t suffice• UITableViewCell has a content view property
■ Add additional views to the content view
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = ...;CGRect frame = cell.contentView.bounds;
UILabel *myLabel = [[UILabel alloc] initWithFrame:frame];myLabel.text = ...;[cell.contentView addSubview:myLabel];
[myLabel release];}
65Saturday, January 30, 2010
![Page 172: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/172.jpg)
66Saturday, January 30, 2010
![Page 173: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/173.jpg)
66Saturday, January 30, 2010
![Page 174: 08 Table Views](https://reader034.vdocument.in/reader034/viewer/2022052522/5538887a5503464e418b47e2/html5/thumbnails/174.jpg)
Questions?
67Saturday, January 30, 2010