UITableView 的使用的小技巧

1、tableView 设置 背景透明
// 非tableView的透明,设置后有Cell的部分不透明,无cell的部分透明(也可设置为类似一个半透明遮罩)
_selectTableV.backgroundView = nil;
_selectTableV.backgroundColor = RGBACOLOR(0, 0, 0, 0);
_selectTableV.opaque = NO;

2、默认选中某个Cell
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    // 默认选中首行
    NSIndexPath *selectedIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [_selectTableV selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
    // cell的选中时变化
    UITableViewCell *cell = (UITableViewCell *)[_selectTableV cellForRowAtIndexPath:selectedIndexPath];
    cell.textLabel.highlightedTextColor = Color_TabBlue;
}

3、cell选中无样式
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

4、cell禁止选中
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row > 2) {
        return indexPath;
    }
    return nil;
}

5、NSIndexPath的创建
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

6、Cell刷新
(1)、刷新指定row或rows
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:selectedIndexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
(2)、刷新某个section内cell
[tableView reloadSections:section withRowAnimation:UITableViewRowAnimationNone];

7、tableView滚动到指定位置
NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:row inSection:section];
            [_tableV scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

// (UITableViewScrollPosition)某个Cell的位置


UITableView 学习推荐

http://www.cnblogs.com/smileEvday/archive/2012/06/28/tableView.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值