gpt4 book ai didi

ios - 奇怪的 UITableView 行为

转载 作者:行者123 更新时间:2023-11-28 11:08:48 27 4
gpt4 key购买 nike

我在 UITableView 中遇到了一个奇怪的错误。我有两个单元格,SummaryHeaderTableViewCellMapTableViewCell。它们有 400 和 200 像素高。我有两行,第一行应该是摘要单元格,第二行应该是 map 单元格。

但是,模拟器中的 View 仍然显示如下:

enter image description here

代码如下:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell: UITableViewCell

if indexPath == 0 {

let summaryCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! SummaryHeaderTableViewCell

summaryCell.nameLabel.text = detailItem!["navn"] as? String
summaryCell.addressLabel.text = "\(detailItem!["adrlinje1"]), \(detailItem!["adrlinje2"])"
summaryCell.cityLabel.text = detailItem!["poststed"] as? String

let inspectionDate: String = detailItem!["dato"] as! String
summaryCell.inspectionDateLabel.text = self.convertDateString(inspectionDate)

cell = summaryCell
}
else
{
let mapCell = tableView.dequeueReusableCellWithIdentifier("MapCell", forIndexPath: indexPath) as! MapTableViewCell

// Set map options

cell = mapCell
}

return cell
}

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if (indexPath.section == 0) {
return 400.0
} else {
return 200.0
}
}

这是带有动态原型(prototype)的 Storyboard:

enter image description here

最佳答案

您应该在 heightForRowAtIndexPath 中引用行而不是节:

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if (indexPath.row == 0) {
return 400.0
} else {
return 200.0
}
}

关于ios - 奇怪的 UITableView 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36314803/

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