Using didSelectRowAtIndexPath

I have a table with 5 cells and if the user clicks my second cell for example, I want to show another table or another page.

Is using

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath` 

the way ?

Answers


Here is an example of navigating to another view controller when the user clicks on the second cell (assuming you have a navigation controller):

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if(indexPath.row == 1){

        MyViewController * vc = [[MyViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];

    }

}

sample Link :http://www.tutorialspoint.com/ios/ios_ui_elements_tableview.htm

 if (indexPath.row ==1)

 {

           //Second cell index path its move another class xib

    classname *yourcontroller = [[classname alloc] initWithNibName:@"xib file name" bundle:nil];

    yourcontroller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentViewController:helpcontroller animated:YES completion:nil];

}

If you are using a Storyboard, you may skip tableView:didSelectRowAtIndexPath: and use prepareForSegue:sender: instead:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"__SEGUE_IDENTIFIER__"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

        SomeOtherViewController *vc = (SomeOtherViewController *)segue.destinationViewController;
            // assign something to vc
    }
}

Need Your Help

How can I extract the file name and extension from a path in C++

c++ string file-io

I have a list of files stored in a .log in this syntax: