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