NNR
NNR

Reputation: 59

Push to different view controller by tapping a cell in Tableviewcontroller

I am developing a application where i implemented a table view controller. Each row of the cell is of type accessory discloser indicator. Now i need to go to different table views by tapping different cells. I hope i should use didSelectRowAtIndexPath: method to do this. But it acts good for navigating to only one view. How can i navigate for different views by tapping different cells. Any help regarding this is really appreciable.

Thanks

Upvotes: 0

Views: 280

Answers (1)

Himanshu A Jadav
Himanshu A Jadav

Reputation: 2306

You can use .row property of NSIndexPath.

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
          [tableView deselectRowAtIndexPath:indexPath animated:TRUE];
          if(indexPath.row==0){
              //Push View Controller 1
          }
          else if(indexPath.row==2){
              //Push View Controller 2
          }
         //You can also use switch() instead of if
    }

if you want an event for tapping on accessory you can use following method.

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath

And dont forget to bind dataSource and delegate properties of the tableview. For more info you can see document here. HTH.

Upvotes: 1

Related Questions