More Related Content More from Oleg Parinov (20) занятие74. Content Size
контент
contentSize.width
contentSize.height
6. Content Inset contentSize.width
contentInset.top
contentSize.height
contentInset.bottom
10. contentSize.width
contentInset.top
contentSize.height
contentInset.bottom
contentInset.left contentInset.right
Saturday, January 30, 2010 16
11. как использовать?
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];
scrollView.contentSize = CGSizeMake(500, 500);
12. Делегат
UIScrollViewDelegate
@protocol UIScrollViewDelegate<NSObject>
@optional
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
...
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView;
@end
14. Zoom to Rect
- (void)setZoomScale:(float)scale animated:(BOOL);
- (void)zoomToRect:(CGRect)rect animated:(BOOL);
urday, January 30, 2010 26
17. анатомия TableView
Table View Anatomy
Plain Style
Table Header
Section Header
Table Cell
Section Footer
Section
Table Footer
18. анатомия TableView
Table View Anatomy
Grouped Style
Table Header
Section Header
Table Cell
Section Footer
Section
Table Footer
19. использование
TableView
• использование делегатов,
предоставляющих данные
• просит то, что сейчас нужно
21. Datasource Message Flow
numberOfSectionsInTableView:
How many
sections?
Datasource
Saturday, January 30, 2010 41
22. Datasource Message Flow
tableView:numberOfRowsInSection:
How many rows
in section 0?
Datasource
Saturday, January 30, 2010 42
23. Datasource Message Flow
tableView:cellForRowAtIndexPath:
What to display at
section 0, row 0?
Datasource
Saturday, January 30, 2010 43
24. 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];
}
25. 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 - любой
26. Cell Styles
initWithStyle - UITableViewCellStyle
UITableViewCellStyleDefault
UITableViewCellStyleSubtitle
UITableViewCellStyleValue1
UITableViewCellStyleValue2
27. 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”;
28. 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;
...
}
30. добавление по ходу
- (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;
33. обычно...
- (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];
}
35. Хранение данных
Property Lists
• Property Lists - для небольшого объема
• Writing an Array to Disk
хранит обычные форматы данных iOS
NSArray *array = [NSArray arrayWithObjects:@“Foo”,
[NSNumber numberWithBool:YES],
[NSDate dateWithTimeIntervalSinceNow:60],
nil];
[array writeToFile:@“MyArray.plist” atomically:YES];
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
! <string>Foo</string>
! <true/>
! <date>2010-02-02T09:26:18Z</date>
</array>
</plist>
Editor's Notes \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n