【发布时间】:2018-05-18 02:42:16
【问题描述】:
我有一个像上图一样的表格视图单元格。我为公寓的租户制作了一个应用程序来报告房间设施的缺陷。如果缺陷已修复,来自服务器的数据将给出defect.status == 2(如果defect.status == 1,仍处于待修复过程中),届时我将显示用户的评论/回复,如果他们满意与否.在他们通过按“是”或“否”做出响应后。 UIView 应该被删除,我的意思是 UIView 包含“你满意”标签和如下所示的 Yes No Button 并且不会再次出现
我在 indexPath 方法的 cellForRow 中使用下面的代码
if dataDefect.status == 2 {
cell.commentResponseView.removeFromSuperview()
}
这是我在视图控制器中的代码:
extension RequestDefectVC : UITableViewDataSource {
//MARK: Table View Delegate & Datasource
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return listDefects.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "defectCell", for: indexPath) as! RequestDefectCell
let dataDefect = listDefects[indexPath.row]
cell.defectData = dataDefect
if dataDefect.status == 3 {
cell.commentResponseView.removeFromSuperview()
}
// to implement button delegate on RequestDefectCell Delegate
cell.cellYesButtonDelegate = self
cell.cellNoButtonDelegate = self
cell.tag = indexPath.row
return cell
}
}
这是我的表格视图单元格中的代码:
protocol RequestDefectCellYesButtonDelegate : class {
func yesButtonDidPressed(defectID: Int)
}
protocol RequestDefectCellNoButtonDelegate : class {
func noButtonDidPressed(defectID: Int)
}
class RequestDefectCell: UITableViewCell {
@IBOutlet weak var defectImageView: DesignableImageView!
@IBOutlet weak var defectStatusLabel: UILabel!
@IBOutlet weak var defectCreationDateLabel: UILabel!
@IBOutlet weak var unitLabel: UILabel!
@IBOutlet weak var defectDescriptionLabel: UILabel!
@IBOutlet weak var commentResponseView: UIView!
@IBOutlet weak var defectStatusLogo: UIImageView!
weak var cellYesButtonDelegate: RequestDefectCellYesButtonDelegate?
weak var cellNoButtonDelegate: RequestDefectCellNoButtonDelegate?
@IBAction func yesButtonDidPressed(_ sender: Any) {
guard let defectData = defectData else {return}
cellYesButtonDelegate?.yesButtonDidPressed(defectID: defectData.defectID)
}
@IBAction func noButtonDidPressed(_ sender: Any) {
guard let defectData = defectData else {return}
cellNoButtonDelegate?.noButtonDidPressed(defectID: defectData.defectID)
}
}
我知道它可能会,因为我已经将它连接到单元格
@IBOutlet weak var commentResponseView: UIView!
但如果我不连接,我没有任何其他想法
【问题讨论】:
-
commentResponseView连接到插座检查一下 -
也可以根据状态显示/隐藏查看
-
感谢您的回答 Darwish,但我需要将其从超级视图中删除,因为如果我只是隐藏它,它将在标签“Keran Patah”与表格视图单元格的底部视图之间保留一个空格.
-
commentResponseView 为什么你的单元格中没有连接到 IBoutlet
-
为什么不改变表格视图后面的数据呢?要么从
listDefects中删除条目,要么设置一些东西来表明缺陷已得到修复。那么您需要做的就是致电reloadData?
标签: ios swift uitableview