什么是UITableView
- 在iOS中,要實現(xiàn)表格數(shù)據(jù)展示,最常用的做法就是使用UITableView
- UITableView繼承自UIScrollView,因此支持垂直滾動,而且性能極佳
如何展示數(shù)據(jù)
- UITableView需要一個數(shù)據(jù)源(dataSource)來顯示數(shù)據(jù)
- UITableView會向數(shù)據(jù)源查詢一共有多少行數(shù)據(jù)以及每一行顯示什么數(shù)據(jù)等
- 沒有設(shè)置數(shù)據(jù)源的UITableView只是個空殼
- 凡是遵守UITableViewDataSource協(xié)議的OC對象,都可以是UITableView的數(shù)據(jù)源
tableView展示數(shù)據(jù)的過程
- 調(diào)用數(shù)據(jù)源的下面方法得知一共有多少組數(shù)據(jù)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
-調(diào)用數(shù)據(jù)源的下面方法得知每一組有多少行數(shù)據(jù)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
- 調(diào)用數(shù)據(jù)源的下面方法得知每一行顯示什么內(nèi)容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
tableView如何顯示數(shù)據(jù)
? ? ?- 設(shè)置dataSource數(shù)據(jù)源
? ? ?- 數(shù)據(jù)源要遵守UITableViewDataSource協(xié)議
? ? ?- 數(shù)據(jù)源要實現(xiàn)協(xié)議中的某些方法
//?告訴tableView一共有多少組數(shù)據(jù)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
//?告訴tableView第section組有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
//?告訴tableView第indexPath行顯示怎樣的cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//告訴tableView第section組的頭部標(biāo)題
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
// 告訴tableView第section組的尾部標(biāo)題
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section ?