gpt4 book ai didi

ios - 你能在自定义单元格中制作 TableView 吗?

转载 作者:行者123 更新时间:2023-11-28 23:20:19 25 4
gpt4 key购买 nike

我有一个自定义的 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。这可能吗?

谢谢!

最佳答案

你绝对可以在 UITableViewCells 中放置一个 UITableView

将 .delegate = self 放在哪里取决于您如何创建单元格。

如果您以编程方式创建它,则使用 override init

 override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
tableView = UITableView()
tableView.delegate = self
tableView.dataSource = self
}

但是,如果您从 nib 或 Storyboard加载单元格,则使用 initWithCoder

-(id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
tableView = UITableView()
tableView.delegate = self
tableView.dataSource = self
}
return self;
}

请注意,您正在为一条崎岖不平的道路做好准备。尽管如此,还是有可能的,祝你好运!

关于ios - 你能在自定义单元格中制作 TableView 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59727037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com