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

UITableView和UITableViewCell的一点使用小总结

2012-06-13 11:54 441 查看
开发一款ipad应用程序,开始接触ios,网上调查了很多信息,非常感谢有那么多网友的帮助。

在这里也把自己用到的总结一下,方便自己和其它网友查询。

自定义UITableViewCell的使用

1:视图中使用多个TableView,设置tag来区分。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(tableView.tag == 1 )
{
}
}


2:TableViewCell选中不高亮显示

cell.selectionStyle = UITableViewCellSelectionStyleNone;


3:TableViewCell的背景色设置

cell.contentView.backgroundColor = [UIColor blackColor];


如果自定义颜色

cell.contentView.backgroundColor = [UIColor colorWithRed:0.898 green:0.898 blue:0.898 alpha:1.0];//#eeeeee


4:选中高亮背景色设置(黑色)

UIView* bgView = [[UIView alloc] init] ;
bgView.frame = CGRectMake(10, 5, 140, 30);
[bgView setBackgroundColor:[UIColor colorWithWhite:2 alpha:0.2]];
[cell setSelectedBackgroundView:bgView];
cell.selectedBackgroundView.backgroundColor = [UIColor blackColor];


5:默认选中TableViewCell第一行(section 0, row0)

[tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:0];
NSIndexPath   *ip = [NSIndexPath indexPathForRow:0 inSection:0];//获得选中的第几行


6:多余的空白Cell不显示

tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
UIView *v1 =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 155, 1)];
v1.backgroundColor = [UIColor whiteColor];
[tableView setTableFooterView:v1];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: