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

前端 未结 9 1293
梦如初夏
梦如初夏 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:22

    This was the one the things that I got problem when I first start. Here is my code that I use for this. In subviewcontroller I have my own constructor like

    -(id)initWithName:(NSString*)naMe
    {
         name=naMe;
         return self;
    }
    

    And in didSelectRowAtIndexPath Delegate method Of UITableView. I alloc it

     MyListView mylistview=[[MyListView alloc] initWithName:@"name"];
    
    [self.navigationController pushViewController:mylistview animated:YES];
    
    [mylistview  release];
    
    0 讨论(0)
  • 2020-12-21 18:30
     NSInteger row = indexPath.row;
    
    
    
    UIViewController *newFrontController = nil;
    
     if (row == 0)
        {
            YourViewController *yourViewController = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:nil];
            newFrontController = [[UINavigationController alloc] initWithRootViewController:peopleViewController];
            [self.navigationController setNavigationBarHidden:YES];
        }  else if(row == 1){
    //do your code
    }
    

    do this in didSelectRowAtIndexPath in tableView.

    0 讨论(0)
  • 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!

    0 讨论(0)
提交回复
热议问题