开发者

Specifying navigation buttons

I am making a Navigation based application and i've noticed a flaw in my app. Even though i have multiple buttons, each having its own title the button leads you to the same screen no matter what button i press. Is there a way to make sure that each button leads to a page specific to the button pressed. Such as clicking Options and it bringing you to the option menu not clicking images and it bringing you to the options menu. Any help would be appreciated Thank you. This is my stack popping method:

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

    Anotherviewcontroller *detailViewController = [[Anotherviewcontroller alloc] initWithNibName:@"Anotherviewcontroller" bundle:nil];

    detailViewController.currentItem = @"Years";

    [self.navigationController pushViewController:detailViewController ani开发者_如何学编程mated:YES];

    [detailViewController release];

}


You should use the indexPath to determine which button/cell has been selected and then, maybe with a switch statement if there are alot, create the the appropriate controller.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
      if(indexPath.row == 0) {
         Anotherviewcontroller *detailViewController = [[Anotherviewcontroller alloc] initWithNibName:@"Anotherviewcontroller" bundle:nil];
         detailViewController.currentItem = @"Years";
         [self.navigationController pushViewController:detailViewController animated:YES];
         [detailViewController release];

      } else {
         MessageViewController *messageViewController = [[MessageViewController alloc] initWithNibName:@"Messageviewcontroller" bundle:nil];
         [self.navigationController pushViewController:messageViewController animated:YES];
         [messageViewController release];
      }
}


You can set indexPath.row as a tag of each btn when you are creating cells and then in didSelectRowAtIndexPath you can check for that tag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜