如何在UITableViewCellAcessoryCheckMark中使用该方法?在ObjC中,我很清楚,但是斯威夫特不能这样做。我的意图是做一个比较,这是真正的车痕出现。
发布于 2014-08-26 15:03:51
在Swift中,要引用UITableViewCellAccessoryCheckMark使用
cell.accessoryType = UITableViewCellAccessoryType.Checkmark
这是苹果的文档:ref/swift/enum/UITableViewCellAccessoryType
在Swift 4/5,
cell.accessoryType = UITableViewCell.AccessoryType.checkmark发布于 2017-03-11 18:09:35
以下是Swift 3的工作答案:
import UIKit
class ViewController: UITableViewController {
let foods = ["apple", "orange", "banana", "spinach", "grape"]
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return foods.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->
UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = foods[indexPath.row]
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
if tableView.cellForRow(at: indexPath)?.accessoryType == UITableViewCellAccessoryType.checkmark
{
tableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCellAccessoryType.none
}
else
{
tableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCellAccessoryType.checkmark
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}https://stackoverflow.com/questions/25509014
复制相似问题