Ios UITableViewDelegate是否影响tableViews行高?
我将在tableView上设置UITableViewDelegate,但如果这样做,行高将发生变化: 第一个pic没有授权;第二次授权(顺便说一句,缺少服务1是正确的) 行高的代码:Ios UITableViewDelegate是否影响tableViews行高?,ios,swift,Ios,Swift,我将在tableView上设置UITableViewDelegate,但如果这样做,行高将发生变化: 第一个pic没有授权;第二次授权(顺便说一句,缺少服务1是正确的) 行高的代码: internal func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { if cellSubTitle.count == 0 { return 70
internal func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if cellSubTitle.count == 0 {
return 70
} else {
if cellSubTitle[indexPath.row] == "" {
return 70
} else {
return 88
}
}
}
对于tableView:
private lazy var tableView: StandardTV = {
let tv = StandardTV()
tv.translatesAutoresizingMaskIntoConstraints = false
tv.headerType = .none
tv.cellTitle = ["Service 2", "Service 3", "Service 4", "Service 5", "Service 6", "Service 7"]
// tv.delegate = self
return tv
}()
我希望有人能帮我:)
编辑
rowForHeight代码是TableView类(“StandardTV”)的一部分。这个类有自己的委托
class StandardTV: UITableView, UITableViewDelegate, UITableViewDataSource {
override init(frame: CGRect, style: UITableViewStyle) {
super.init(frame: CGRect.zero, style: .grouped)
delegate = self
dataSource = self
backgroundColor = .white
translatesAutoresizingMaskIntoConstraints = false
separatorStyle = .none
showsVerticalScrollIndicator = false
self.register(StandardTVCell.self, forCellReuseIdentifier: reuseIdentifier)
}
....
}
第二个代码段来自我插入tableView的视图控制器。感谢@maddy和@Swift Rabbit的提示,我得到了一个答案:是的,cource影响代理行高度:) 我已经为tableView实现了两次委托方法。一个在我的“StandardTV”类中,另一个在viewController上。因此,我假设我的“StandardTV”类中的第一个代理将被忽略,因此行高度也将被忽略
顺便说一句:我在不同的viewController中使用这些“StandardTV”类,希望保持相同的行高。您实现了
行高
,您想知道为什么高度会发生变化?这就是委托方法的要点。没有委托,tableView不会要求它的委托函数heightForRowAt中高度的行。。。所以,是的,行为将不一样。@maddy谢谢你的提示。我的错误是两次使用代理。在我上面的代码中插入委托,这将是第二次,我想它将“覆盖”第一个委托?!