UITableView
UITableView
基本操作
1. 调整layout
点击storyboard下面的小按钮添加AutoLayout约束,调整顶部margin为20(这个距离恰好不被statusBar挡住)。
注意:如果使用代码添加tableView就需要在代码中添加约束
2.遵守代理协议
让ViewController遵守UITableViewDataSource协议 需要在didload方法中发送tableView setDataSource = self。
注意:可以在storyboard中设置TableView的outlet:datasource
也可以让ViewController遵守代理协议UITableViewDelegate协议
在didload方法中设置tableView的代理。
**注意:可以在storyboard中设置TableView的outlet:delegate
3. 实现协议方法
@required
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
// Row display. Implementers should *always* try to reuse cells by setting each cell\'s reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;