苹果官网 demo The Elements 阅读随笔

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; . //将dataSource 指定为其他类, 可以在其他类中实现 UITableViewDataSource 中的方法
详见: 苹果官方demo The Elements 在ElementsSortedByNameDataSource 类中实现UITableViewDataSource 的方法. .
AtomicElement 数据控制类:
AtomicElementTileView 类声明 AtomicElement 类型的属性
使用self.语法直接对其赋值 elementTileView.element = _element; . 使用 prepareForSegue 进行界面跳转
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender segue.destinationViewController 要跳转到的controller
segue.sourceViewController 资源controller (将要从这个controller进行跳转) .
(self.statesDictionary)[@"Solid"] = [NSMutableArray array]; //self.statesDictionary 这个字典本身无 Solid 这个 key ,
但是此语法将 在self.statesDictionary 添加 以 Solid 为key 以后面创建的数组 [NSMutableArray array] 为value . . 使用(self.nameIndexesDictionary)[aKey] 这类语法(糖衣语法),
()- (NSArray *)elementsWithInitialLetter:(NSString*)aKey { return (self.nameIndexesDictionary)[aKey];
}
() (self.elementsDictionary)[anElement.name] = anElement;
(),() 可以看出 (self.nameIndexesDictionary)[aKey] 这种语法既 self.nameIndexesDictionary[aKey] 将其对应的value 取出来 然后经行 set 方法取值 和 get 方法赋值. . 从demo中获益最大的就是tableView.dataSource 可以指定为单独的一个类来控制 self.tableView 这样可以是Controller 可与 数据处理类 区分开来,
是controller类中的代码更加简洁. 同理 delegate 也应该可以用此种方法实现. . 顺便记录一下 demo的项目文件夹结构.
()Classes{
Application Support { }
TableView Representations{
View Controllers{ }
User Interface Elements{ }
Data Sources{ }
}
Single Element View {
User Interface Elements{ }
Data Sources{ }
}
Data Model{ }
}
()Other Sources{ }
()Resources{ }
上一篇:windows转mac-开发环境搭建(一):需要搭建的环境及安装的工具


下一篇:html中的元素和节点