在Swift中静态TableView中的特定单元格的披露指标
问题描述:
我创建了一个静态TableView,我想添加或删除披露指标,具体取决于我们是在咨询我们自己的帐户还是访客帐户。在Swift中静态TableView中的特定单元格的披露指标
这是我想什么:
let index = IndexPath(row: 4, section: 0)
let cell = tableView.cellForRow(at: index)
if currentUser {
cell.accessoryType = .none
//cell.backgroundColor = UIColor.red
}
我试图把它放在viewDidLoad中的功能,但没有奏效。我也试过cellForRowAt indexPath和相同的结果。
我该怎么做?
答
只需检查是否要在cellForRowAt indexPath方法中显示披露指标。
if (wantsToShow){ // Your condition goes here
cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
}
else{
cell.accessoryType = .none
}
就是这样。
+0
问题是,它是一个静态的TableView,我只想在单元[0,4]上做这个... – KevinB
答
请使用下面的代码在cellForRowTableView代码
它会为你
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
if currentUser {
// Own Account
cell.accessoryType = .none
//cell.backgroundColor = UIColor.red
}else{
//Guest Account
cell.accessoryType =.checkmark
}
}
,是有其他的?这只是删除配件...你在哪里设置它? –
如果单元格是静态的,则使用IBOutlet来直接访问单元格。 – vadian