UITableView

UITableView

基本操做

1. 調整layout

點擊storyboard下面的小按鈕添加AutoLayout約束,調整頂部margin爲20(這個距離剛好不被statusBar擋住)。性能

注意:若是使用代碼添加tableView就須要在代碼中添加約束優化

2.遵照代理協議

讓ViewController遵照UITableViewDataSource協議 須要在didload方法中發送tableView setDataSource = self。ui

注意:能夠在storyboard中設置TableView的outlet:datasource代理

也可讓ViewController遵照代理協議UITableViewDelegate協議
在didload方法中設置tableView的代理。code

**注意:能夠在storyboard中設置TableView的outlet:delegateget

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;

性能優化

相關文章
相關標籤/搜索