您的位置:首页 > 其它

设置cell选中颜色以及表格默认选中某行

2014-11-21 10:06 495 查看
1.在加载cell的地方(即 (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath里面)加上下面几句代码

[cell setBackgroundColor:CLEARCOLOR];

cell.selectedBackgroundView = [[UIView
alloc]
initWithFrame:cell.frame];

cell.selectedBackgroundView.backgroundColor =
COLOR(255,
255,
255, 1.0);

2.制定表格默认选中某一行

//设置选中第一行
[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]];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: