Viknesh k m
Viknesh k m

Reputation: 9

how to navigate from one table view controller to another table view controller in xcode

I am working on a project where there arises a situation that I want to move from one table view controller to another table view controller

(ie) when I click on any cell in the table view it should go to another table view.I also need for each different cell you click on the table view you get taken to another table view.i don't know how to do it

1.how to link the two table view controller

2.what would be the code for that

please help me

Upvotes: 0

Views: 590

Answers (2)

Ashish Sharma
Ashish Sharma

Reputation: 663

make your first table, add prototype cell, from that cell create a segue to your second table, after that write this code :

     override func prepare(for segue: UIStoryboardSegue, sender: Any!)  
{
            if segue.identifier == "secondTable" //secondTable is identifier for Segue from prototype cell of 1st table to 2nd table.

            {
                let selectedRow = tableView.indexPathForSelectedRow?.row
                let viewController = segue.destination as! seocondViewController //secondViewController is your class for 2nd table.
               // If you also want to pass some data then add that code also.
                }}

This is just the concept. if you want a more clear answer try posting your complete code. If you just want the logic, here it is. This is a link to similar project which has a table and when any row is clicked , it will pass you to another view, which is Web view related to that specific row , every row has a different link, though it is not a Table view, but you can get the concept at least.

Upvotes: 1

user7571182
user7571182

Reputation:

The model for a table view is an array.You can try something like this.

id anyPartOfMyM = [self.arrayA objectAtIndex:sIndexPath.row];
[self.arrayA removeObject:anyPartOfMyM];
[self.arrayB addObject:anyPartOfMyM];

// the simplest way to update the tables.
[self.tableViewA reloadData];
[self.tableViewB reloadData];

Hope this helps....

Upvotes: 0

Related Questions