UITableView

来源:互联网 发布:中美对抗 知乎 编辑:程序博客网 时间:2024/05/21 05:24


如何展示数据

UITableView需要一个数据源(dataSource)来显示数据


UITableView会向数据源查询一共有多少行数据以及每一行显示什么数据等


没有设置数据源的UITableView只是个空壳


凡是遵守UITableViewDataSource协议的OC对象,都可以是UITableView的数据源


UITableViewDataSource协议

// 一共有多少组数据

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;

// 每一组有多少行数据

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

// 每一行显示什么内容

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

UITableView

@property (nonatomicassignid <UITableViewDataSource> dataSource;


tableView展示数据的过程



调用数据源的下面方法得知一共有多少组数据

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;


调用数据源的下面方法得知每一组有多少行数据

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;


调用数据源的下面方法得知每一行显示什么内容

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;


UITableView

ableView


UITableView

UITableVi

0 0