Swift 中静态 TableView 中特定单元格的披露指示器
Disclosure indicator to specific cell in static TableView in 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
}
就是这样。
请在 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
}
}
您正在使用静态单元格,因此 cellForRow
不会被调用。相反,只需拖动连接您的单元格并进行设置,就像这样
为了在特定静态单元格上添加附件,我使用了 tableView、cellForRowAt,但我无法访问对 UITableViewCell 的引用。
然后我找到了super.tableView(tableView, cellForRowAt: indexPath)
所以这是我的代码:
假设您知道所需的特定索引路径:
var indexPathSort = IndexPath(item: 0, section: 0)
var indexPathPrice = IndexPath(item: 0, section: 1)
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = super.tableView(tableView, cellForRowAt: indexPath)
if indexPath == indexPathSort || indexPath == indexPathPrice {
cell.accessoryType = .checkmark
}
return cell
}
Swift
Specific cell
if indexPath.row == 1 {
cell.accessoryType = .disclosureIndicator
} else {
cell.accessoryType = .none
}
我创建了一个静态 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
}
就是这样。
请在 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
}
}
您正在使用静态单元格,因此 cellForRow
不会被调用。相反,只需拖动连接您的单元格并进行设置,就像这样
为了在特定静态单元格上添加附件,我使用了 tableView、cellForRowAt,但我无法访问对 UITableViewCell 的引用。
然后我找到了super.tableView(tableView, cellForRowAt: indexPath)
所以这是我的代码: 假设您知道所需的特定索引路径:
var indexPathSort = IndexPath(item: 0, section: 0)
var indexPathPrice = IndexPath(item: 0, section: 1)
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = super.tableView(tableView, cellForRowAt: indexPath)
if indexPath == indexPathSort || indexPath == indexPathPrice {
cell.accessoryType = .checkmark
}
return cell
}
Swift
Specific cell
if indexPath.row == 1 {
cell.accessoryType = .disclosureIndicator
} else {
cell.accessoryType = .none
}