UITableView和UITableViewCell的一点使用小总结

开发一款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];


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值