gpt4 book ai didi

swift - 我想在单元格顶部放置一个特定值

转载 作者:行者123 更新时间:2023-11-30 10:47:34 24 4
gpt4 key购买 nike

我想将服务器中的特定值放置在 TableView 的顶部,即第一行我想将用户的反馈放在表格 View 的顶部

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
tableView.tableFooterView = UIView(frame: .zero)
if let cell = tableView.dequeueReusableCell(withIdentifier: "AllFeedbackCell", for: indexPath) as? AllFeedbackCell {
cell.feedback = feedbacks?[indexPath.row]
return cell
}
return UITableViewCell()
}
 var feedback: Feedback? {
didSet {
if let username = feedback?.username, !username.isEmpty {
userEmailLabel.text = username
} else {
if let userEmail = feedback?.email, let emailIndex = userEmail.range(of: "@")?.upperBound {
userEmailLabel.text = String(userEmail.prefix(upTo: emailIndex)) + "..."
}
}
feedbackDateLabel.text = feedback?.timeStamp.getFirstChar(10)
userFeedbackLabel.text = feedback?.feedbackString
if let avatarURLString = feedback?.avatar {
let imageURL = URL(string: avatarURLString)
gravatarImageView.kf.setImage(with: imageURL)
}
roundedCorner()
}
}
}

实际上,我正在从用户那里获取所有反馈,并且我希望用户反馈位于最顶部的单元格,以便我可以实现编辑和删除反馈功能。

最佳答案

如果我理解正确,您想在 tableView 中引入一个不同的单元格,该单元格与其他单元格不同并放置在顶部,对吗?话虽如此,您需要第二个 UITableViewCell,在方法中执行此操作后:cellForRowAt do

if indexPath.row == 0 {
let cell = tableView.dequeReusableCell(withReuseIdentifier: TopCellId, for indexPath) as! TopCell

//here you update NewCell's properties with your code

return cell
} else {
let cell = tableView.dequeReusableCell(withReuseIdentifier: RegularCellId, for: indexPath) as! RegularCell

// Here you update the cell which will be used for the rest of the tableView

return cell
}

可能您也可以使用 TableViewHeader,但您的问题有点令人困惑。

关于swift - 我想在单元格顶部放置一个特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55444018/

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