OC开发_Storyboard——UITableView

本文详细介绍了UITableView的数据源设置方法,包括dataSource的实现、delegate协议的应用、segue的使用、加载中的spinner效果及数据重新加载的方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

一、tableView

1、datasource数据源

(1 构造每一个tableVIewCell的方法:cellForRowAtIndexPath,这里的

     dequeueReusableCellWithIdentifier会根据识别ID去取storyBoard中的cell,同时这也是利用取缓存中的cell复用

 

 (2 还包含了另外两个方法,numberOfSectionsInTableView 默认是返回1如果不重写它的话;numberOfRowsInSection是没有默认值的,所以实现数据源的时候这个是必须实现的

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

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

 

2、delegate 协议,方法有很多,这里仅仅举例两个

 (1 比如用户点了哪一行?做了什么操作?

   - (void)tableView:(UITableView *)sender didSelectRowAtIndexPath:(NSIndexPath *)path

 (2  每个cell的图标的点击如下图:

         - (void)tableView:(UITableView *)sender accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath         

 

3、segue 点击cell跳转的时候,

    比如跳转到另外一个segue,那么对应的 prepareForSegue就应该知道是哪一个cell的点击,所以sender参数就起到了这个作用

   我们可以利用 NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];

 

4、加载中的spinner

    @property (strong) UIRefreshControl *refreshControl;

    开启加载动画: - (void)beginRefreshing;

    结束加载动画:- (void)endRefreshing;

 当然需要启动配置:

       

5、reloadData重新加载数据

  - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths  withRowAnimation:(UITableViewRowAnimation)animationStyle;

详情的tableView方法可以参考之前写的这篇文章:http://www.cnblogs.com/daomul/p/4370128.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值