Search code examples
swiftuibuttonshowuistoryboardsegue

press a button in tableviewCell and perform another controller


I have one UIButton in a tableviewcell which setted "show segue" in the mainStoryBoard. And I want to press this button and perform new controller, so how can I do this?


Solution

  • //there are many ways to do it 1 of the way is: // take the button outlet in 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)
        }