如何在表格视图中修复空单元格?

时间:2015-10-21 20:28:51

标签: ios swift uitableview

由于某种原因,我的表格视图中的某些单元格显示为空白。不是全部,只是其中一些。

你能看看我的cellForRowAtIndexPath并告诉我如何解决这个问题吗?此应用程序从API获取JSON数据并将其解析为本地对象。

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

    let row = indexPath.row

    guard let cell = tableView.dequeueReusableCellWithIdentifier(CurrentIssueArticlesTableCellIdentifier, forIndexPath: indexPath) as? CurrentIssueArticlesTableViewCell else {

        print ("error: currentIssueTableView cell is not of class CurrentIssueArticlesTableViewCell, we will use EditorialsTableViewCell instead")
        return tableView.dequeueReusableCellWithIdentifier(CurrentIssueArticlesTableCellIdentifier, forIndexPath: indexPath) as! EditorialsTableViewCell
    }

    guard currentIssueObjects.count - 1 > indexPath.row else {
        return cell
    }

    let currentIssueObject = currentIssueObjects.objectAtIndex(indexPath.row) as! IssueElement

        let title = currentIssueObject.title ?? ""

        let timeStampDateObject = NSDate(timeIntervalSince1970: NSTimeInterval(currentIssueObject.timeStamp))
        let timeStampDateString = dateFormatter.stringFromDate(timeStampDateObject) ?? "Date unknown"


    if let author = currentIssueObject.author {

        cell.currentIssueArticlesAuthorLabel!.font = UIFont.preferredFontForTextStyle(UIFontTextStyleSubheadline)
        cell.currentIssueArticlesAuthorLabel!.text = author

    } else {
        return cell
    }


        let issueNumber = currentIssueObject.issueNumber ?? ""
        let volumeNumber = currentIssueObject.volumeNumber ?? ""

        let articleContent = currentIssueObject.articleContent ?? ""

        let nodeID = currentIssueObject.nodeID ?? 0

        cell.currentIssueArticlesHeadlineLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline)
        cell.currentIssueArticlesHeadlineLabel.text = title



        cell.currentIssueArticlesPublishDateLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleSubheadline)
        cell.currentIssueArticlesPublishDateLabel.text = timeStampDateString

        if row == 0 {

            cell.userInteractionEnabled = false

            let imageURL = (currentIssueObjects.objectAtIndex(row) as! IssueElement).imageURL

            cell.currentIssueArticlesHeadlineLabel.textColor = UIColor.clearColor()
            cell.currentIssueArticlesAuthorLabel.textColor = UIColor.clearColor()
            cell.currentIssueArticlesPublishDateLabel.textColor = UIColor.clearColor()

            cell.request?.cancel()

            if let image = self.imageCache.objectForKey(imageURL!) as? UIImage {
                cell.currentIssueArticlesBackgroundImageView.image = image
            } else {
                cell.currentIssueArticlesBackgroundImageView.image = UIImage(named: "reveal Image")
                cell.request = Alamofire.request(.GET, imageURL!).responseImage() { response in
                    if response.result.error == nil && response.result.value != nil {

                        self.imageCache.setObject(response.result.value!, forKey: response.request!.URLString)

                        cell.currentIssueArticlesBackgroundImageView.image = response.result.value
                    } else {

                    }

                }
            }


        }

        else {



        }

    return cell
}

0 个答案:

没有答案