在iOS中要實(shí)現(xiàn)表格數(shù)據(jù)展示,最常用到的就是UITableView
是iOS比較重要的控件
- UITableView繼承于UIScrollView
- UItableView默認(rèn)是垂直滾動(dòng)
UITableView的兩種樣式
- UITableViewStylePlain
- UITableViewStyleGrouped
UITableView如何展示數(shù)據(jù)
-
UITableView需要一個(gè)數(shù)據(jù)源(dataSource)來顯示數(shù)據(jù),類似于代理,且做為。
- 設(shè)置數(shù)據(jù)源,只要遵守UITableViewDataSource協(xié)議的OC對(duì)象都可做為其數(shù)據(jù)源。沒有設(shè)置數(shù)據(jù)源的tableView只是個(gè)空殼。
self.tableView.dataSource=self;
```
- UITableView如果想要顯示數(shù)據(jù),就會(huì)調(diào)用數(shù)據(jù)源對(duì)象的某個(gè)方法,通過返回值來知道數(shù)據(jù)的相關(guān)信息。遵守協(xié)議且能實(shí)現(xiàn)方法就能做為tableView的數(shù)據(jù)源。
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
-(NSInteger)numberOfSectionInTableView:(UITableView *)tableView;
-(UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath{
}