The Elements
https://developer.apple.com/library/ios/samplecode/TheElements/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007419
UINavigationController *navController = [storyboard instantiateViewControllerWithIdentifier:@"navForTableView"];
ElementsTableViewController *viewController =
(ElementsTableViewController *)[navController topViewController]; // 1. [navController topViewController]
id<ElementsDataSource, UITableViewDataSource> dataSource;
dataSource = [[ElementsSortedByNameDataSource alloc] init];
viewController.dataSource = dataSource; 2. //将dataSource 指定为其他类, 可以在其他类中实现 UITableViewDataSource 中的方法
详见: 苹果官方demo The Elements
在ElementsSortedByNameDataSource 类中实现UITableViewDataSource 的方法.
3.
AtomicElement 数据控制类:
AtomicElementTileView 类声明 AtomicElement 类型的属性
使用self.语法直接对其赋值
elementTileView.element = _element;
4. 使用 prepareForSegue 进行界面跳转
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
segue.destinationViewController 要跳转到的controller
segue.sourceViewController 资源controller (将要从这个controller进行跳转)
5.
(self.statesDictionary)[@"Solid"] = [NSMutableArray array]; //self.statesDictionary 这个字典本身无 Solid 这个 key ,
但是此语法将 在self.statesDictionary 添加 以 Solid 为key 以后面创建的数组 [NSMutableArray array] 为value .
6. 使用(self.nameIndexesDictionary)[aKey] 这类语法(糖衣语法),
(1)- (NSArray *)elementsWithInitialLetter:(NSString*)aKey {
return (self.nameIndexesDictionary)[aKey];
}
(2) (self.elementsDictionary)[anElement.name] = anElement;
(1),(2) 可以看出 (self.nameIndexesDictionary)[aKey] 这种语法既 self.nameIndexesDictionary[aKey] 将其对应的value 取出来 然后经行 set 方法取值 和 get 方法赋值.
7. 从demo中获益最大的就是tableView.dataSource 可以指定为单独的一个类来控制 self.tableView 这样可以是Controller 可与 数据处理类 区分开来,
是controller类中的代码更加简洁. 同理 delegate 也应该可以用此种方法实现.
8. 顺便记录一下 demo的项目文件夹结构.
(1)Classes{
Application Support {
}
TableView Representations{
View Controllers{
}
User Interface Elements{
}
Data Sources{
}
}
Single Element View {
User Interface Elements{
}
Data Sources{
}
}
Data Model{
}
}
(2)Other Sources{
}
(3)Resources{
}