iOS UITableView 设置默认选中行及其颜色
2017-06-15 15:41
1131 查看
//在创建UITableView或获取数据的地方设置默认选中一行,这里默认选中第一行
[self.tableView
selectRowAtIndexPath:[NSIndexPath
indexPathForItem:0
inSection:0]
animated:YES
scrollPosition:UITableViewScrollPositionTop];
if ([self.tableView.delegate
respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) {
[self.tableView.delegate
tableView:self.tableView
didSelectRowAtIndexPath:[NSIndexPath
indexPathForItem:0
inSection:0]];
}
//设置选中颜色是在以下执行的
-(UITabl
4000
eViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
static
NSString * cellId =
@"SortTableViewCell";
UITableViewCell * cell = [tableView
dequeueReusableCellWithIdentifier:cellId];
if (cell ==
nil) {
cell = [[UITableViewCell
alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellId];
}
cell.selectedBackgroundView = [[UIView
alloc]
initWithFrame:cell.frame];
cell.selectedBackgroundView.backgroundColor =[UIColor
whiteColor];
return cell;
}
[self.tableView
selectRowAtIndexPath:[NSIndexPath
indexPathForItem:0
inSection:0]
animated:YES
scrollPosition:UITableViewScrollPositionTop];
if ([self.tableView.delegate
respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) {
[self.tableView.delegate
tableView:self.tableView
didSelectRowAtIndexPath:[NSIndexPath
indexPathForItem:0
inSection:0]];
}
//设置选中颜色是在以下执行的
-(UITabl
4000
eViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
static
NSString * cellId =
@"SortTableViewCell";
UITableViewCell * cell = [tableView
dequeueReusableCellWithIdentifier:cellId];
if (cell ==
nil) {
cell = [[UITableViewCell
alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellId];
}
cell.selectedBackgroundView = [[UIView
alloc]
initWithFrame:cell.frame];
cell.selectedBackgroundView.backgroundColor =[UIColor
whiteColor];
return cell;
}
相关文章推荐
- ios tableView设置cell选中颜色以及表格默认选中某行
- ios 设置UITableView 选中行cell的背景颜色(自定义选中的背景颜色)
- iOS UITableView 和 UICollectionView 设置默认选中状态
- iOS设置UITableView中Cell被默认选中后怎么触发didselect事件
- IOS开发入门:在Storyboard中为UITableView中的static cells设置选中背景色selectedBackgroundColor
- ios UITableView默认选中第一行
- IOS UITableView 选中一行后,不显示选中颜色的方法
- IOS UITableView颜色设置的实例详解
- IOS学习笔记-UITableView表索引的颜色设置
- IOS开发之----设置UITableView背景色和选中背景色
- iOS 设置UITabBar,背景颜色,默认图片,文字颜色,和选中颜色.
- ios UITableView separatorColor 默认颜色
- iOS小技巧-UITableView取消或设置cell的选中效果
- 设置UITableView中单元格的默认选中
- iOS小技巧-UITableView去除底部多余的分割线方法以及设置分割线风格和颜色
- iOS中设置tableview的选中时的文字颜色
- iOS 7 UITableview 在Plain模式下 设置背景颜色无效
- iOS-UITableView 设置分割线长度和颜色
- IOS开发相关07--UITableView默认选中第一个cell
- IOS tableView 选中时的背景颜色设置