选中变灰色和向左滑动多一个删除按钮

iOS 码拜 9年前 (2015-04-30) 966次浏览 0个评论
 

选中变灰色和向左滑动多一个删除按钮

如题,如何让这个页面刚一进来就选中一个并且选中的时候这一行变灰,cell里面怎么写
还有就是按钮向左滑动的时候就变灰

请详细些

选中变灰色和向左滑动多一个删除按钮
20分
UITableView 是支持多选的,你要先把这个属性设为 NO:allowsMultipleSelection,禁止多选。
然后设置 Cell 的 selectedBackgroundView,或者把selectionStyle设为UITableViewCellSelectionStyleGray,你可以先看看效果。
最后,在 TableView 的 didSelect 这个 delegate 方法里,不要调用deselectRowAtIndexPath方法,让 TableView 对 Cell 保持选中。
ps:通过 TableView 的indexPathForSelectedRow方法,你可以知道当前有没有 Cell 被选中以及选中的是哪一个。
选中变灰色和向左滑动多一个删除按钮
20分
在viewDidAppear:这个方法中来处理第一行选中的操作。
viewDidAppear 是在viewDidLoad执行结束以后才被调用,保证uitableview的数据已被加载完毕

- (void)selectFirstRow
{
     if ([self.tableView numberOfSections] > 0 && [self.tableView numberOfRowsInSection:0] > 0) {
          NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
          [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop];
     }
}

在CellForRowAtIndexPath: 返回cell时,设置cell被选中时样式
UIView *bgView = [UIView new];
bgView.backgroundColor = [UIColor grayColor];
bgView.frame = ..
cell.selectedBackgroundView = bgView;
其中的label 高亮
cell.label..highlightedTextColor = [UIColor whiteColor];

选中变灰色和向左滑动多一个删除按钮
引用 2 楼 zhanglei5415 的回复:

在viewDidAppear:这个方法中来处理第一行选中的操作。
viewDidAppear 是在viewDidLoad执行结束以后才被调用,保证uitableview的数据已被加载完毕

- (void)selectFirstRow
{
     if ([self.tableView numberOfSections] > 0 && [self.tableView numberOfRowsInSection:0] > 0) {
          NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
          [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop];
     }
}

在CellForRowAtIndexPath: 返回cell时,设置cell被选中时样式
UIView *bgView = [UIView new];
bgView.backgroundColor = [UIColor grayColor];
bgView.frame = ..
cell.selectedBackgroundView = bgView;
其中的label 高亮
cell.label..highlightedTextColor = [UIColor whiteColor];

那向左滑动多出一个删除按钮呢? 而且向左滑动后背景色又变回白色了

选中变灰色和向左滑动多一个删除按钮
20分
引用 3 楼 qq379271395 的回复:
Quote: 引用 2 楼 zhanglei5415 的回复:

在viewDidAppear:这个方法中来处理第一行选中的操作。
viewDidAppear 是在viewDidLoad执行结束以后才被调用,保证uitableview的数据已被加载完毕

- (void)selectFirstRow
{
     if ([self.tableView numberOfSections] > 0 && [self.tableView numberOfRowsInSection:0] > 0) {
          NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
          [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop];
     }
}

在CellForRowAtIndexPath: 返回cell时,设置cell被选中时样式
UIView *bgView = [UIView new];
bgView.backgroundColor = [UIColor grayColor];
bgView.frame = ..
cell.selectedBackgroundView = bgView;
其中的label 高亮
cell.label..highlightedTextColor = [UIColor whiteColor];

那向左滑动多出一个删除按钮呢? 而且向左滑动后背景色又变回白色了

滑动删除:http://rainbird.blog.51cto.com/211214/634587/

选中变灰色和向左滑动多一个删除按钮
20分
滑动删除直接用系统的就行了

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明选中变灰色和向左滑动多一个删除按钮
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!