IOS学习:基本控件(UITableView)




一、UITableViewDataSource的方法

// 必须要实现的方法

@required

// UITableView可以存在多个组,这个方法返回指定组(section)中有多少条记录

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


// 这个方法返回的是每一个行的布局,数据也要在这里面绑定,如果要自定义布局,则这个方法返回自定义的UITableViewCell

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


// 可选方法

@optional

// 此方法返回当前UITableView有多少个组,如果不改写这个方法,则默认值为1

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

             

// 这个方法返回开头的组名,字体样式是固定的,如果要改样式,则要改写UITableViewDelegate中的viewForHeaderInSection方法

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;   

 

// 这个方法返回组结尾时显示的名字,如上图中的fone, ftwo

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;


// Editing


// 返回row是否可以编辑,默认为可以编辑,此方法一般不用

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;


// 返回row是否可以移动,在UITableView要实现一些动画时,会用到,此方法一般不用

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;


// 返回section的titles列表

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;  

    

// tell table which section corresponds to section title/index (e.g. "B",1)) 

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;  


// 下面两个方法,是数据处理相关的

// Data manipulation - insert and delete support 


// After a row has the minus or plus button invoked (based on the UITableViewCellEditingStyle for the cell), the dataSource must commit the change

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;


// Data manipulation - reorder / moving support


- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;


二、UITableViewDelegate常用方法

// 这个方法返回每个UITableViewCell的高度,如果要改变cell的高度,要在这里返回修改后的高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;


// 当点击某个cell时触发此方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath



三、点击cell后放开时自动取消选中


     在 didSelectRowAtIndexPath方法中,调用 deselectRowAtIndexPath方法取消选中即可。


     代码如下:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    // 取消选中

    [self.tableViewdeselectRowAtIndexPath:indexPath animated:YES];

}


四、一些实用的小知识点

1、去除cell之间的间隔线(气泡聊天的时候会用到)

      tableView.separatorStyle = NO;


基于html+python+Apriori 算法、SVD(奇异值分解)的电影推荐算法+源码+项目文档+算法解析+数据集,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用,详情见md文档 电影推荐算法:Apriori 算法、SVD(奇异值分解)推荐算法 电影、用户可视化 电影、用户管理 数据统计 SVD 推荐 根据电影打分进行推荐 使用 svd 模型计算用户对未评分的电影打分,返回前 n 个打分最高的电影作为推荐结果 n = 30 for now 使用相似电影进行推荐 根据用户最喜欢的前 K 部电影,分别计算这 K 部电影的相似电影 n 部,返回 K*n 部电影进行推荐 K = 10 and n = 5 for now 根据相似用户进行推荐 获取相似用户 K 个,分别取这 K 个用户的最喜爱电影 n 部,返回 K*n 部电影进行推荐 K = 10 and n = 5 for now Redis 使用 Redis 做页面访问次数统计 缓存相似电影 在使用相似电影推荐的方式时,每次请求大概需要 6.6s(需要遍历计算与所有电影的相似度)。 将相似电影存储至 redis 中(仅存储 movie_id,拿到 movie_id 后还是从 mysql 中获取电影详细信息), 时间缩短至:93ms。 十部电影,每部存 top 5 similar movie 登录了 1-6 user并使用了推荐系统,redis 中新增了 50 部电影的 similar movie,也就是说,系统只为 6 为用户计算了共 60 部电影的相似度,其中就有10 部重复电影。 热点电影重复度还是比较高的
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值