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

问题描述 投票:0回答:2

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

swift uibutton show uistoryboardsegue
2个回答
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)
    }

0
投票

请在tableview单元格中使用自定义委托,

请按照以下链接,

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

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

performSegue(withIdentifier: "identifier", sender: self)
© www.soinside.com 2019 - 2024. All rights reserved.