您的位置:首页 > 产品设计 > UI/UE

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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: