哈06-自定义UITableViewCell选中效果

来源:互联网 发布:手机淘宝每次都要登录 编辑:程序博客网 时间:2024/05/22 14:42
1、首先设置

xxxxtableview.separatorStyle=UITableViewCellSelectionStyleNone;

不然cell被重用后,会被还原为默认选中效果

2、在

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath中设置

cell.selectedBackgroundView=nil;

这步非常关键不然,之后后出现两个被选中的cell,

3在

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{中自定义选中效果,以及其他其他需要

例如:

UITableViewCell *cell=[tableViewcellForRowAtIndexPath:indexPath];


UIImageView *bgView=[[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"selected_bg"]];

        bgView.frame=CGRectMake(10,0, kDeviceWidth-100, cell.frame.size.height);

        bgView.contentMode=UIViewContentModeScaleAspectFit;

       cell.selectedBackgroundView=bgView;

4、在

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath同时也设置

UITableViewCell *cell=[tableViewcellForRowAtIndexPath:indexPath];


cell.selectedBackgroundView=nil;

这样就可以啦,


0 0
原创粉丝点击