【问题标题】:Set title of UIButton that's located in a UICell设置位于 UICell 中的 UIButton 的标题
【发布时间】:2016-09-03 21:59:13
【问题描述】:

我不明白为什么我不能设置我的UIButton 的标题。它在这里崩溃:

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    if(section == 0) {
        let view = UIView()
        view.alpha = 0
        return kTableHeaderShouldStickToTop ? view : carouselViewController.view
    } else {
        let cell = tableView.dequeueReusableCellWithIdentifier("NewsFeedSectionHeaderCell") as! NewsFeedSectionHeaderCell
        cell.delegate = self
        cell.dataSource = self

        cell.followingButton.setTitle("test", forState: .Normal)
        return cell
    }
}

在我的.xib文件中连接:

【问题讨论】:

  • 您是否检查过它是否与 IBOutlet 类连接?
  • 是的,这也是我最初的回应。
  • 请检查哪个方法首先调用 cellForRow 或 viewForHeaderInSection 因为你正在做的是必须有单元格

标签: ios iphone swift uitableview uibutton


【解决方案1】:

请检查我们是否可以在 viewForHeaderInSection: 方法中获取单元格对象,因为据我所知 viewForHeaderInSection: 在 cellForRowAtIndexPath。在

处设置断点
let cell = tableView.dequeueReusableCellWithIdentifier("NewsFeedSectionHeaderCell") as! NewsFeedSectionHeaderCell

然后从变量 View(左侧到我们看到日志的控制台)检查或将鼠标悬停在该对象上以查看该对象是否为 nil。它将为零,因此会引发异常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-21
    • 1970-01-01
    • 1970-01-01
    • 2013-03-06
    • 2019-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多