Search code examples
ios6sqliteuitableview

iOS6 Pass Row Number from Cell to next View Controller


I have a basic table view cell that is all SQLite3 database generated.

When I click on the Disclosure Indicator in a cell to move to a View Controller so I can edit the contents of the previous cell, how can I just pass the row# or the id# over?

Is there a cute way of doing this in iOS6?

EH


Solution

  • You can use didSelectRowAtIndexPath method of UITableView delegate for your purpose

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
          /* your other stuff */
          NSLog ( @\"You selected row: %d\", indexPath.row ); // Gives you row#
    }
    

    To pass row# to another DetailViewController, Add following line in DetailViewController.h file

    @property (readwrite) int selectedRow;
    

    And synthsis it in DetailViewController.m file

    @synthesize selectedRow;
    

    Now you can use selectedRow by creating object of DetailViewController like,

    [detailViewController setSelectedRow:indexPath.row];