我有一个自定义TableViewCell
。在此里面,我想再放一个TableView
,但是我遇到了问题。
我有这样的东西:
import UIKit
class ByteCell: UITableViewCell, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var title: UILabel!
@IBOutlet weak var game: UIImageView!
@IBOutlet weak var TableView: UIView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
}
首先,我不会写:
tableView.delegate = self
tableView.dataSource = self
在这里的任何地方,所以我根本无法修改tableView。
第二,确实出现的TableView
,没有任何行并且不能滚动。我本质上是想在TableView
内部的自定义单元格内创建可滚动的TableView
。
这可能吗?
谢谢!
答案 0 :(得分:1)
您绝对可以将UITableView放在UITableViewCells中
.delegate = self的放置位置取决于您如何创建单元。
如果您是通过编程方式创建的,则可以使用override init
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
tableView = UITableView()
tableView.delegate = self
tableView.dataSource = self
}
但是,如果您从笔尖或情节提要中加载单元格,请使用initWithCoder
-(id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
tableView = UITableView()
tableView.delegate = self
tableView.dataSource = self
}
return self;
}
仅需注意,您正准备走上坎bump的道路。尽管如此,这完全有可能会带来好运!