tableViewCell 简单使用

作者: Yanni_L | 来源:发表于2015-07-26 01:48 被阅读369次

tableView的注意点

  • 1.如果在一个控制器中添加了两个tableView而且还有导航栏,那么肯定会有一个tableView的上面会被遮挡,那么我们就可以使用代码将tableView向下移动
// 设置当前tableView向下偏移64
    self.userTableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);
  • 3.可以设置默认选中的行,并且选择显示的位置
// 默认选中0组0行
[self.TableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionMiddle]
  • 4.代理方法点击tableView就会调用此方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  • 5.刷新tableView
    [self reloadData]

tableViewCell 的使用注意点

  • 1.tableViewCell 里面有三个基本常用的属性
    // 设置图片
    self.imageView.image
    // 设置子标题
    self.detailTextLabel.text
    // 设置主标题
    self.textLabel.text

    1. 如果点击了cell就会调用cell的方法,如果想要设置cell里面的一些属性就可以从写这个方法
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    // 需要调用父类的方法
    [super setSelected:selected animated:YES];

    // 设置当前cell里面的一些属性的隐藏
    self.selectIndicator.hidden = !selected;

    // 设置字体的颜色
    self.textLabel.textColor = selected ? self.selectIndicator.backgroundColor: viewBackGroundColor(78, 78, 78);

    }

    1. 想要更改cell里面控件的尺寸就可以从写方法
// 从新调整label的位置大小
- (void)layoutSubviews
{
     // 必须调用super 的方法
      [super layoutSubviews];

    // 更改y值
    self.textLabel.y = 2;

    // 更改高度
    self.textLabel.height = self.contentView.height - 2 * self.textLabel.y;
}

相关文章

网友评论

    本文标题:tableViewCell 简单使用

    本文链接:https://www.haomeiwen.com/subject/vurmqttx.html