tableView的选中问题

1.[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 这个只是设置选择的时候的样式,而不是禁止点击选择。 cell没有选中的阴影

2.- (void)collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath   选中状态  

- (void)collectionView:(UICollectionView*)collectionView didDeselectItemAtIndexPath:(NSIndexPath*)indexPath  取消选中状态

在我们点击cell的时候这两个方法的执行顺序是先取消在选中 当然也可以手动去调用这个方法 ,tableView是多选的,在小位计步问题中当点击了一个cell 我另外手动又didSelect一次cell,再次点击cell时,系统默认先取消的是之前点击的cell而非我手动设置点击的cell

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];if ([myTableView.delegate respondsToSelector:@selector(tableView:willSelectRowAtIndexPath:)]) {

    [myTableView.delegate tableView:self.tableView willSelectRowAtIndexPath:indexPath];

}

[myTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition: UITableViewScrollPositionNone];

  if ([myTableView.delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) {

    [myTableView.delegate tableView:self.tableView didSelectRowAtIndexPath:indexPath];

}

还有一种默认选中的方法:可以放在reloadData之后

NSIndexPath *ip=[NSIndexPath indexPathForRow:0 inSection:0];

[tableView selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionBottom];

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一、简介 <<UITableView(或简单地说,表视图)的一个实例是用于显示和编辑分层列出的信息的一种手段 <<...
    无邪8阅读 13,647评论 3 3
  • { 24、Sqlite数据库 1、存储大数据量,增删改查,常见管理系统:Oracle、MSSQLServer、DB...
    CYC666阅读 4,531评论 0 1
  • 1.nav1.navigationBar.barStyle=UIBarStyleBlack; //改变导航栏背景颜...
    SadMine阅读 5,637评论 1 4
  • #pragma mark someValueAboutTableView 1.tableView的样式:UITab...
    潇岩阅读 4,553评论 0 0
  • 版权声明:未经本人允许,禁止转载. 1. TableView初始化 1.UITableView有两种风格:UITa...
    萧雪痕阅读 7,896评论 2 10