squeek school #5
DESCRIPTION
TRANSCRIPT
![Page 1: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/1.jpg)
Разработка приложений для iOSЗанятие #5
squeek school
понедельник, 16 мая 2011 г.
![Page 2: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/2.jpg)
Табличное представление + скроллинг
• UITableView
• UIScrollView
• делегаты
понедельник, 16 мая 2011 г.
![Page 3: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/3.jpg)
TableViewTable View Styles
UITableViewStylePlain UITableViewStyleGrouped
32Saturday, January 30, 2010
понедельник, 16 мая 2011 г.
![Page 4: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/4.jpg)
анатомия TableView
Table Cell
Table Footer
Table HeaderSection Header
Section Footer
Section
Table View AnatomyPlain Style
34Saturday, January 30, 2010понедельник, 16 мая 2011 г.
![Page 5: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/5.jpg)
Table Cell
Table Footer
Table Header
Section Header
Section Footer
Section
Table View AnatomyGrouped Style
35Saturday, January 30, 2010
анатомия TableView
понедельник, 16 мая 2011 г.
![Page 6: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/6.jpg)
использование TableView
• использование делегатов, предоставляющих данные
• просит то, что сейчас нужно
понедельник, 16 мая 2011 г.
![Page 7: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/7.jpg)
UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)table;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
понедельник, 16 мая 2011 г.
![Page 8: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/8.jpg)
Datasource Message Flow
Datasource
How many sections?
numberOfSectionsInTableView:
41Saturday, January 30, 2010
понедельник, 16 мая 2011 г.
![Page 9: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/9.jpg)
Datasource Message Flow
Datasource
tableView:numberOfRowsInSection:
How many rows in section 0?
42Saturday, January 30, 2010
понедельник, 16 мая 2011 г.
![Page 10: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/10.jpg)
Datasource Message Flow
Datasource
tableView:cellForRowAtIndexPath:
What to display at section 0, row 0?
43Saturday, January 30, 2010
понедельник, 16 мая 2011 г.
![Page 11: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/11.jpg)
NSIndexPath• массив int
• секция + строка
• [NSIndexPath indexPathForRow:(NSUInteger)row inSection:(NSUInteger)section];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = ...; cell.textLabel.text = [myStrings objectAtIndex:indexPath.row] return [cell autorelease];
}
понедельник, 16 мая 2011 г.
![Page 12: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/12.jpg)
reuse - чтобы быстрее- (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;
}
identifier - любой
понедельник, 16 мая 2011 г.
![Page 13: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/13.jpg)
initWithStyle - UITableViewCellStyleCell Styles
UITableViewCellStyleDefault
UITableViewCellStyleSubtitle
UITableViewCellStyleValue1
UITableViewCellStyleValue2
62Saturday, January 30, 2010
понедельник, 16 мая 2011 г.
![Page 14: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/14.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
понедельник, 16 мая 2011 г.
![Page 15: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/15.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
понедельник, 16 мая 2011 г.
![Page 16: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/16.jpg)
перезагрузить
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.tableView reloadData];}
понедельник, 16 мая 2011 г.
![Page 17: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/17.jpg)
добавление по ходу
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
понедельник, 16 мая 2011 г.
![Page 18: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/18.jpg)
UITableViewDelegate
• поведение + внешний вид
• логика отдельно от данных!
понедельник, 16 мая 2011 г.
![Page 19: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/19.jpg)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
выбор строки
понедельник, 16 мая 2011 г.
![Page 20: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/20.jpg)
обычно...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = indexPath.row id objectToDisplay = [myObjects objectAtIndex:row];
MyViewController *myViewController = ...; myViewController.object = objectToDisplay;[self.navigationController pushViewController:myViewController animated:YES];
}
понедельник, 16 мая 2011 г.
![Page 21: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/21.jpg)
UITableViewController= UITableView + делегаты
понедельник, 16 мая 2011 г.
![Page 22: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/22.jpg)
UIScrollViewScrolling Examples
8Saturday, January 30, 2010
понедельник, 16 мая 2011 г.
![Page 23: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/23.jpg)
контентContent Size
contentSize.height
contentSize.width
9Saturday, January 30, 2010
понедельник, 16 мая 2011 г.
![Page 24: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/24.jpg)
Content Inset
contentInset.bottom
contentInset.top
13Saturday, January 30, 2010
понедельник, 16 мая 2011 г.
![Page 25: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/25.jpg)
Content Inset
contentSize.height
contentSize.width
contentInset.top
contentInset.bottom
10Saturday, January 30, 2010
понедельник, 16 мая 2011 г.
![Page 26: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/26.jpg)
начало скролла
scrollIndicatorInsets.top
Scroll Indicator Insets
14Saturday, January 30, 2010
понедельник, 16 мая 2011 г.
![Page 27: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/27.jpg)
ContentOffset
15Saturday, January 30, 2010
понедельник, 16 мая 2011 г.
![Page 28: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/28.jpg)
contentOffset.y
contentOffset.x
17Saturday, January 30, 2010
понедельник, 16 мая 2011 г.
![Page 29: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/29.jpg)
contentSize.height
contentSize.width
contentInset.top
contentInset.bottom
contentInset.left contentInset.right
16Saturday, January 30, 2010понедельник, 16 мая 2011 г.
![Page 30: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/30.jpg)
как использовать?
CGRect frame = CGRectMake(0, 0, 200, 200); UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:frame]; frame = CGRectMake(0, 0, 500, 500); UIImage *image = [UIImage imageNamed:@"tree.jpg"]; UIImageView *myImageView = [[UIImageView alloc] initWithImage:image]; myImageView.frame = frame; [scrollView addSubview:myImageView];
scrollView.contentSize = CGSizeMake(500, 500); [self.view addSubview:scrollView];
понедельник, 16 мая 2011 г.
![Page 31: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/31.jpg)
Делегат UIScrollViewDelegate
@protocol UIScrollViewDelegate<NSObject>@optional
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;...
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView; @end
понедельник, 16 мая 2011 г.
![Page 32: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/32.jpg)
Масштабирование
scrollView.maximumZoomScale = 2.0; scrollView.minimumZoomScale = scrollView.frame.size.width /myImage.frame.size.width;
и реализовать метод делегата:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)view {return someViewThatWillBeScaled;
}
понедельник, 16 мая 2011 г.
![Page 33: Squeek School #5](https://reader036.vdocuments.mx/reader036/viewer/2022062418/553888104a79598f768b4786/html5/thumbnails/33.jpg)
- (void)zoomToRect:(CGRect)rect animated:(BOOL);
Zoom to Rect
27Saturday, January 30, 2010
- (void)setZoomScale:(float)scale animated:(BOOL);
Set Zoom Scale
26Saturday, January 30, 2010
понедельник, 16 мая 2011 г.