修复错误`没有重复使用的表格单元的索引路径`后,节标题单元格不适合视图?

时间:2016-01-15 15:17:11

标签: ios swift uitableview custom-cell

50我的部分标题单元格的高度为UITableViewController我会通过override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return normalCellHeight } 中的方法以编程方式更改:

no index path for table cell being reused

与此同时,我收到错误Main.storyboard,因此我使用this post来修复错误。

但是在使用that post修复该错误后,现在我的部分标题没有调整大小以适应视图。它是used to look like this,但现在它looks like this.正如您所看到的那样,我的标题标题不适合高度并在屏幕宽度方向上移动。

我知道我可以通过将76中的标题标题单元格的高度设置为override func viewDidLoad() { super.viewDidLoad() normalCellHeight = (view.bounds.height - self.navigationController!.navigationBar.bounds.height - 15)/(CGFloat(self.dayOfWeek.count) + 1) } override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { if section == lastCellIndex{ let header = tableView.dequeueReusableCellWithIdentifier("allExpensesCell") as!AllExpensesCell let view = UIView(frame: header.frame) view.addSubview(header) return view } else{ let header = tableView.dequeueReusableCellWithIdentifier("headerCell") as! SummaryHeaderTableViewCell header.delegate = self header.index = section let day = dayOfWeek[section] header.dayOfWeek.text = day.rawValue.uppercaseString header.dayOfWeek.backgroundColor = colorOfDay[day] header.totalCost.text = "$\(totalSpentPerDay[section])" header.totalCostView.backgroundColor = colorOfDay[day] let view = UIView(frame: header.frame) print("Header frame height: \(header.frame.height)") print("Header frame width: \(header.frame.width)") print("Screen width: \(view.bounds.width)") view.addSubview(header) return view } } override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { print("Header height: \(normalCellHeight)") return normalCellHeight } 来解决高度问题。但这并不理想,因为我希望我的所有节标题单元格都填满整个视图高度,每个标题单元格的高度会从iPhone 5变为iPhone 6. {{3}这是奇怪的b / c视图的宽度和标题视图的框架宽度是相同的(见下文)。 you can see, it doesn't fix the width issue

代码:

Header height: 76.0 //This prints 48 times
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header height: 76.0
Header frame height: 50.0 //These 3 lines print 7 times, which makes sense b/c I have 7 sections
Header frame width: 600.0
Screen width: 600.0
Header frame height: 50.0
Header frame width: 600.0
Screen width: 600.0
Header frame height: 50.0
Header frame width: 600.0
Screen width: 600.0
Header frame height: 50.0
Header frame width: 600.0
Screen width: 600.0
Header frame height: 50.0
Header frame width: 600.0
Screen width: 600.0
Header frame height: 50.0
Header frame width: 600.0
Screen width: 600.0
Header frame height: 50.0
Header frame width: 600.0
Screen width: 600.0

控制台:

{
  "id": "5644596f9bf67301645999d9",
  "headline": "Scientists Look Beyond Solar System to Study Planet",
  "renditions": {
    "baseImage": {
      "height": 933,
      "href": "www.imgur.com/animage",
      "mimetype": "image/jpeg",
      "width": 1400
    },
    "preview": {
      "height": 500,
      "href": "www.imgur.com/animage",
      "mimetype": "image/jpeg",
      "width": 400
    },
    "thumbnail": {
      "height": 150,
      "href": "www.imgur.com/animage",
      "mimetype": "image/jpeg",
      "width": 125
    }
  }
}

0 个答案:

没有答案