专业java、php、iOS、C++、网页设计、平面设计、网络营销、游戏开发、前端与移动开发培训机构
自定义HMStatusCell
- 自定义
HMStatusCell
显示显示原创微博
内容 - 创建
HMStatusOriginalCell.xib
, 并设置内容 - 关联
HMStatusOriginalCell.xib
的Cell
为HMStatusCell
- 拖线
HMStatusOriginalCell.xib
到HMStatusCell
在
HMHomeViewController
注册HMStatusOriginalCell.xib
到tableView
, 并设置tableView
的rowHeight
和estimatedRowHeight
override func viewDidLoad() { super.viewDidLoad() ... // 注册可重用 cell tableView.register(UINib(nibName: "HMStatusOriginalCell", bundle: nil), forCellReuseIdentifier: "OriginalCell") tableView.rowHeight = UITableViewAutomaticDimension tableView.estimatedRowHeight = 200 ... }
在
HMHomeViewController
的tableView
获取到自定义的Cell
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "OriginalCell", for: indexPath) as! HMStatusCell return cell }
- 运行: 效果如下