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

来源:互联网 发布:c语言输出 编辑:程序博客网 时间:2024/05/18 00:10

1.在加载cell的地方(即 (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath里面)加上下面几句代码

        [cell setBackgroundColor:CLEARCOLOR];

        cell.selectedBackgroundView = [[UIViewalloc] initWithFrame:cell.frame];

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


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

//设置选中第一行  

            [self.tableView selectRowAtIndexPath:[NSIndexPathindexPathForItem:0inSection:0]animated:YESscrollPosition:UITableViewScrollPositionTop];

           if ([self.tableView.delegaterespondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)])

            {

                [self.tableView.delegatetableView:self.tableView didSelectRowAtIndexPath:[NSIndexPathindexPathForItem:0inSection:0]];

            }



0 0