按下tableviewCell中的按钮并执行另一个控制器

时间:2019-03-28 05:51:46

标签: swift uibutton show uistoryboardsegue

我在一个tableviewcell中有一个UIButton,它在mainStoryBoard中设置了“ show segue”。我想按此按钮并执行新的控制器,那么我该怎么做?

2 个答案:

答案 0 :(得分:1)

//有很多方法可以做到这一点: //在tableviewcell中取按钮出口

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell2 : cellname = tableView.dequeueReusableCell(withIdentifier: "cellname") as! cellname
    cell2.addAddressButton.addTarget(self, action: #selector(openNewVC), for: .touchUpInside) 
    return cell2
}

func openNewVC(){
        self.performSegue(withIdentifier: "Identifiername", sender: self)
    }

答案 1 :(得分:0)

请在表格视图单元格中使用自定义委托,

请点击以下链接

https://medium.com/@jamesrochabrun/implementing-delegates-in-swift-step-by-step-d3211cbac3ef

现在,在视图控制器中,内部委托函数使用

performSegue(withIdentifier: "identifier", sender: self)