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

UITableView 的使用的小技巧

2015-09-05 17:24 507 查看
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 学习推荐

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