如何让UIBarButtonItem打开一个新的视图控制器?

时间:2012-01-03 18:18:25

标签: iphone

我想添加按下此信息按钮时打开新视图控制器的方法。

  UIBarButtonItem *infoItem = [[UIBarButtonItem alloc] 
                          initWithTitle:@"Info" 
                          style:UIBarButtonItemStyleBordered 
                          target:nil 
                          action:@selector(action)]; 

1 个答案:

答案 0 :(得分:2)

-(void)action {
   MyViewController *myView = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
   [myView presentModalViewController:YES]; // present view modally
   [self.navigationController pushViewController:myView animated:YES]; // add to navigation stack
   [myView release];
}