gpt4 book ai didi

ios - 预期返回 'UITableViewCell' 的函数中缺少返回值

转载 作者:行者123 更新时间:2023-11-30 13:59:24 25 4
gpt4 key购买 nike

编辑 1:修改后的代码 - 仍然不起作用。

我有两个自定义单元格。

第一个单元格(且仅第一个单元格)的类型为 CurrentIssueFrontCoverTableViewCell,其余单元格的类型为 CurrentIssueArticlesTableViewCell。在声明我的 cellForRowAtIndexPath 函数时,我收到标题中描述的错误。有办法解决这个问题吗?为什么它没有检测到我正在“if”循环中返回单元格?

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

let row = indexPath.row

if indexPath.row == 0 {

let cellWithCoverImage = tableView.dequeueReusableCellWithIdentifier(CurrentIssueFrontCoverTableCellIdentifier, forIndexPath: indexPath) as! CurrentIssueFrontCoverTableViewCell

if let currentIssueFrontCoverObject = currentIssueObjects.objectAtIndex(indexPath.row) as? IssueElement {

let title = currentIssueFrontCoverObject.title ?? ""

let timeStampDateObject = NSDate(timeIntervalSince1970: NSTimeInterval(currentIssueFrontCoverObject.timeStamp))
let timeStampDateString = dateFormatter.stringFromDate(timeStampDateObject)

let issueNumber = currentIssueFrontCoverObject.issueNumber ?? ""
let volumeNumber = currentIssueFrontCoverObject.volumeNumber ?? ""

let nodeID = currentIssueFrontCoverObject.nodeID ?? 0

let imageURL = currentIssueFrontCoverObject.imageURL ?? ""


cellWithCoverImage.request?.cancel()

if let coverImage = self.imageCache.objectForKey(imageURL) as? UIImage {
cellWithCoverImage.currentIssueFrontCoverImageView.image = coverImage
} else {
cellWithCoverImage.currentIssueFrontCoverImageView.image = nil
cellWithCoverImage.request = Alamofire.request(.GET, imageURL).responseImage() { response in
if let coverImage = response.result.value {
self.imageCache.setObject(response.result.value!, forKey: imageURL)
cellWithCoverImage.currentIssueFrontCoverImageView.image = coverImage

} else {

}
}
}
} else {

}

return cellWithCoverImage

// Populating data in the "Articles" type cells

} else if indexPath.row >= 1 {

let cellWithoutCoverImage = tableView.dequeueReusableCellWithIdentifier(CurrentIssueArticlesTableCellIdentifier, forIndexPath: indexPath) as! CurrentIssueArticlesTableViewCell

if let currentIssueArticleObject = currentIssueObjects.objectAtIndex(indexPath.row) as? IssueElement {

let title = currentIssueArticleObject.title ?? ""

let timeStampDateObject = NSDate(timeIntervalSince1970: NSTimeInterval(currentIssueArticleObject.timeStamp))
let timeStampDateString = dateFormatter.stringFromDate(timeStampDateObject)

let author = currentIssueArticleObject.author ?? ""

let issueNumber = currentIssueArticleObject.issueNumber ?? ""
let volumeNumber = currentIssueArticleObject.volumeNumber ?? ""

let articleContent = currentIssueArticleObject.articleContent ?? ""

let nodeID = currentIssueArticleObject.nodeID ?? 0


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

cellWithoutCoverImage.currentIssueArticlesAuthorLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleSubheadline)
cellWithoutCoverImage.currentIssueArticlesAuthorLabel.text = author

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

return cellWithoutCoverImage

} else {

}
}

else {

}
}

编辑 1:修改后的代码 - 仍然不起作用

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

let row = indexPath.row

switch(row) {


case 0:

let cellWithCoverImage = tableView.dequeueReusableCellWithIdentifier(CurrentIssueFrontCoverTableCellIdentifier, forIndexPath: indexPath) as! CurrentIssueFrontCoverTableViewCell

if let currentIssueFrontCoverObject = currentIssueObjects.objectAtIndex(indexPath.row) as? IssueElement {

let title = currentIssueFrontCoverObject.title ?? ""

let timeStampDateObject = NSDate(timeIntervalSince1970: NSTimeInterval(currentIssueFrontCoverObject.timeStamp))
let timeStampDateString = dateFormatter.stringFromDate(timeStampDateObject)

let issueNumber = currentIssueFrontCoverObject.issueNumber ?? ""
let volumeNumber = currentIssueFrontCoverObject.volumeNumber ?? ""

let nodeID = currentIssueFrontCoverObject.nodeID ?? 0

let imageURL = currentIssueFrontCoverObject.imageURL ?? ""


cellWithCoverImage.request?.cancel()

if let coverImage = self.imageCache.objectForKey(imageURL) as? UIImage {
cellWithCoverImage.currentIssueFrontCoverImageView.image = coverImage
} else {
cellWithCoverImage.currentIssueFrontCoverImageView.image = nil
cellWithCoverImage.request = Alamofire.request(.GET, imageURL).responseImage() { response in
if let coverImage = response.result.value {
self.imageCache.setObject(response.result.value!, forKey: imageURL)
cellWithCoverImage.currentIssueFrontCoverImageView.image = coverImage

} else {

return

}
}
}
} else {

break
}

return cellWithCoverImage;

// Populating data in the "Articles" type cells



default:

let cellWithoutCoverImage = tableView.dequeueReusableCellWithIdentifier(CurrentIssueArticlesTableCellIdentifier, forIndexPath: indexPath) as! CurrentIssueArticlesTableViewCell

if let currentIssueArticleObject = currentIssueObjects.objectAtIndex(indexPath.row) as? IssueElement {

let title = currentIssueArticleObject.title ?? ""

let timeStampDateObject = NSDate(timeIntervalSince1970: NSTimeInterval(currentIssueArticleObject.timeStamp))
let timeStampDateString = dateFormatter.stringFromDate(timeStampDateObject)

let author = currentIssueArticleObject.author ?? ""

let issueNumber = currentIssueArticleObject.issueNumber ?? ""
let volumeNumber = currentIssueArticleObject.volumeNumber ?? ""

let articleContent = currentIssueArticleObject.articleContent ?? ""

let nodeID = currentIssueArticleObject.nodeID ?? 0


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

cellWithoutCoverImage.currentIssueArticlesAuthorLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleSubheadline)
cellWithoutCoverImage.currentIssueArticlesAuthorLabel.text = author

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

return cellWithoutCoverImage;

} else {
break
}
}

}

最佳答案

您需要删除代码中的最后一个 else,因为它是空的。您也可以使用switch,例如:

switch(row){
case 0:{
// code with the CurrentIssueFrontCoverTableViewCell

....
return cellWithCoverImage;
}

default:{

// code with the CurrentIssueArticlesTableViewCell

...
return cellWithoutCoverImage;
}
}

关于ios - 预期返回 'UITableViewCell' 的函数中缺少返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33175171/

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