所以我有一个tableview,看起来像这样。
并在我的viewWillAppear函数中使用以下代码。
if (!self.isMovingToParentViewController){
self.categoryDisplayed = ""
self.collectionsDisplayed = ""
self.currencyDisplayed = ""
}
tableView.reloadData()
清除并重新加载tableview,然后,tableview最终看起来像这样。
我不知道为什么会这样,有人可以请帮助:(
这是我的cellForRowAt代码:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "listCell", for: indexPath) as! ListDataTableViewCell
cell.dataTitleLabel.text = dataArray[indexPath.row]
if indexPath.row == 0{
cell.methodType.isHidden = true
cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
cell.optionSelectedLabel.isHidden = false
cell.optionSelectedLabel.text! = categoryDisplayed
cell.optionSelectedLabel.adjustsFontSizeToFitWidth = true
} else if indexPath.row == 1 {
cell.methodType.isHidden = false
cell.methodType.tintColor = UIColor(red:0.00, green:0.74, blue:0.63, alpha:1.0)
cell.optionSelectedLabel.isHidden = true
cell.accessoryType = .none
cell.selectionStyle = .none
} else if indexPath.row == 2{
cell.methodType.isHidden = true
cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
cell.optionSelectedLabel.isHidden = false
cell.optionSelectedLabel.text! = currencyDisplayed
cell.optionSelectedLabel.adjustsFontSizeToFitWidth = true
cell.optionSelectedLabel.minimumScaleFactor = 0.2
} else if indexPath.row == 3{
cell.methodType.isHidden = true
cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
cell.optionSelectedLabel.isHidden = false
cell.optionSelectedLabel.text! = collectionsDisplayed
}
return cell
}