【问题标题】:ios 9 UITableView ghost empty cellsios 9 UITableView 鬼空单元格
【发布时间】:2015-11-23 10:37:38
【问题描述】:

更新到最新的 XCode 7 beta 5 后,我的应用程序表现得很奇怪。发布后我得到了这个:

页面多次更新后:

在几次更新后,该部分再次正常(但其他部分存在错误):

调试器中的所有时间似乎都很好:所有数据都从服务器加载并发送到表...

有人有什么想法吗,为什么会这样?

代码:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell:EventCell = self.contentWindow.dequeueReusableCellWithIdentifier("evcell")! as! EventCell

    let dateFormatter = NSDateFormatter()
    dateFormatter.dateFormat = "HH:mm"
    var index = 0;
    for date in keysSet {

        if (index==indexPath.section)
        {
            cell.timeLabel.text = dateFormatter.stringFromDate(datesOfEvents[date]![indexPath.row].time)
            cell.nameLabel.text = datesOfEvents[date]![indexPath.row].title
            print(index)
            print(cell.nameLabel.text)
            if datesOfEvents[date]![indexPath.row].state == MessageState.SENT {
                cell.nameLabel.textColor = UIColor.blackColor()
            }
            else {
                let currentDate = NSDate()
                if datesOfEvents[date]![indexPath.row].time > currentDate {
                    cell.nameLabel.textColor = UIColor.blueColor()
                }
                else
                {
                    cell.nameLabel.textColor = UIColor.redColor()
                }
            }
            break;
        }
        index++

    }
    //cell.backgroundColor = UIColor(colorLiteralRed: 39, green: 185, blue: 200, alpha: 0)
    //cell.textLabel?.textColor = UIColor(colorLiteralRed: 255, green: 255, blue: 255, alpha: 1)
    cell.textLabel?.numberOfLines = 0;

    return cell
}

【问题讨论】:

  • 尝试使用dequeReusableCellWithIdentifier:forIndexPath 而不是您正在使用的版本。对于单元格重用,您应该使用 forIndexPath 版本。它可能是也可能不是您的问题的一部分。在当前版本中,使用您正在使用的版本返回的单元格没有大小类,而使用 forIndexPath 版本的单元格则没有。轻松更改,先尝试。
  • 这是非常不寻常的代码。为什么会有循环?
  • 而不是一个循环,如果keysSet是一个NSSet,只需使用keysSet.allObjects as Array<NSDate>并在索引indexPath.section处获取日期?你做事的方式很奇怪!

标签: ios objective-c uitableview ios9 xcode7-beta5


【解决方案1】:

我在 iOS 9.1 中也遇到过这个问题。如果您只为每个故事板开发一个设备系列,请尝试在故事板的文件检查器中取消选中“使用大小类”。它为我解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    相关资源
    最近更新 更多