6. использование
TableView
• использование делегатов,
предоставляющих данные
• просит то, что сейчас нужно
понедельник, 16 мая 2011 г.
7. UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)table;
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath;
понедельник, 16 мая 2011 г.
8. Datasource Message Flow
numberOfSectionsInTableView:
How many
sections?
Datasource
Saturday, January 30, 2010 41
понедельник, 16 мая 2011 г.
9. Datasource Message Flow
tableView:numberOfRowsInSection:
How many rows
in section 0?
Datasource
Saturday, January 30, 2010 42
понедельник, 16 мая 2011 г.
10. Datasource Message Flow
tableView:cellForRowAtIndexPath:
What to display at
section 0, row 0?
Datasource
Saturday, January 30, 2010 43
понедельник, 16 мая 2011 г.
12. 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 г.
13. Cell Styles
initWithStyle - UITableViewCellStyle
UITableViewCellStyleDefault
UITableViewCellStyleSubtitle
UITableViewCellStyleValue1
UITableViewCellStyleValue2
понедельник, 16 мая 2011 г.
14. 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”;
понедельник, 16 мая 2011 г.
15. Accessory Types
// UITableView delegate method
- (UITableViewCellAccessoryType)tableView:(UITableView *)table
accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath;
UITableViewCellAccessoryDisclosureIndicator
UITableViewCellAccessoryDetailDisclosureButton
UITableViewCellAccessoryCheckmark
- (void)tableView:(UITableView *)tableView
accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
// Only for the blue disclosure button
NSUInteger row = indexPath.row;
...
}
понедельник, 16 мая 2011 г.
16. перезагрузить
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.tableView reloadData];
}
понедельник, 16 мая 2011 г.
17. добавление по ходу
- (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 г.
18. UITableViewDelegate
• поведение + внешний вид
• логика отдельно от данных!
понедельник, 16 мая 2011 г.
19. выбор строки
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath;
понедельник, 16 мая 2011 г.
31. Делегат
UIScrollViewDelegate
@protocol UIScrollViewDelegate<NSObject>
@optional
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
...
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView;
@end
понедельник, 16 мая 2011 г.
32. Масштабирование
scrollView.maximumZoomScale = 2.0;
scrollView.minimumZoomScale = scrollView.frame.size.width /
myImage.frame.size.width;
и реализовать метод делегата:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)view {
return someViewThatWillBeScaled;
}
понедельник, 16 мая 2011 г.
33. Zoom to Rect
- (void)setZoomScale:(float)scale animated:(BOOL);
- (void)zoomToRect:(CGRect)rect animated:(BOOL);
urday, January 30, 2010 26
day, January мая 2011 г.
понедельник, 16
30, 2010