How can I move to another view controller when the user clicks on a row?

前端 未结 9 1295
梦如初夏
梦如初夏 2020-12-21 17:41

I am new to iPhone development, and I want to move to another page when the user clicks on a particular row. So, if they click on first row, I want the page to redirect to t

9条回答
  •  南方客
    南方客 (楼主)
    2020-12-21 18:34

    @kashyap in didSelectRowAtIndexPath delegate of the UITableView you have to check the conditions that on which indexPath you are clicking and open the viewControllers you had made accordingly

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        // Navigation logic may go here -- for example, create and push another view controller.
    
    
         FirstViewController *firstViewController = [[FirstViewController alloc]        initWithNibName:@"FirstViewController" bundle:nil];
         SecondViewController *secondViewController = [[SecondViewController alloc]        initWithNibName:@"SecondViewController" bundle:nil];
    
         switch (indexPath.row) {
           case 0:
              [self.navigationController pushViewController:firstViewController animated:YES];
              [firstViewController release];
              break;
           case 1:
              [self.navigationController pushViewController:secondViewController animated:YES];
              [secondViewController release];
              break;
         }//Likewise do for the no of rows you have in your `UITableView`
    

    Hope you get my point.....Good Luck!

提交回复
热议问题