为了账号安全,请及时绑定邮箱和手机立即绑定

didSelectRowAtIndexPath无效,Swift 3

didSelectRowAtIndexPath无效,Swift 3

青春有我 2019-09-06 16:10:53
任何人都可以看到为什么世界上没有调用SelectRowAtIndexPath会被调用?我delegate在代码和故事板中都进行了三重检查。class AddCard: UIViewController,UIPopoverPresentationControllerDelegate, UITableViewDataSource, UITableViewDelegate {@IBOutlet weak var cardView: UIView!@IBOutlet weak var tableView: UITableView!let tableItems = ["Background Color","Background Image","Font Style","Font Color"]let cellID = "cell"override func viewDidLoad() {    super.viewDidLoad()    tableView.delegate = self    tableView.dataSource = self}override func didReceiveMemoryWarning() {    super.didReceiveMemoryWarning()    // Dispose of any resources that can be recreated.}func setBackgroundColor (_ color: UIColor) {    cardView.backgroundColor = color}func numberOfSectionsInTableView(tableView: UITableView) -> Int {    return 1}func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {    return tableItems.count}func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {    let cell = tableView.dequeueReusableCell(withIdentifier: cellID, for: indexPath as IndexPath)    let row = indexPath.row    cell.textLabel?.text = tableItems[row]    return cell}func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {    tableView.deselectRow(at: indexPath as IndexPath, animated: true)    print(indexPath.row)    let row = indexPath.row    switch(row){    case 0:        let popoverVC = storyboard?.instantiateViewController(withIdentifier: "colorPickerVC") as! ColorPickerViewController        popoverVC.modalPresentationStyle = .popover        popoverVC.preferredContentSize = CGSize(width: 284, height: 446)        }    }}}
查看完整描述

2 回答

?
芜湖不芜

TA贡献1796条经验 获得超7个赞

Swift 3修改了方法的签名(很多方法,新的“规则”/样式)


替换:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath)用

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)


注意_,didSelectRowAtvs didSelectRowAtIndexPath,就像你更新的其他(也适用于相同的“风格”),但不是这个。


删除该行,让XCode执行自动完成。否则,您可以将其替换为doc中的那个。


查看完整回答
反对 回复 2019-09-06
?
月关宝盒

TA贡献1772条经验 获得超5个赞

您没有更新didSelectRowAtIndexPath:Swift 3 的签名。从DOC: optional func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath),注意到_didSelectRowAtVS didSelectRowAtIndexPath,像其他一个你更新,但不是这一个。删除该行,让XCode执行自动完成。否则,您可以将其替换为doc中的那个。

查看完整回答
反对 回复 2019-09-06
  • 2 回答
  • 0 关注
  • 887 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信