我想从 MainWindow.xib 文件中的条形按钮显示 ModalViewController。我该怎么做?我要使用的基本代码是这样的:
-(IBAction)add {
myCustomViewController *add = [[myCustomViewController alloc] initWithNibName:@"myCustomViewController" bundle:nil];
[self presentModalViewController:add animated:YES];
[add release];
}
但是我把它放在哪里?
编辑:我想通了,在我的导航控制器中,我将以下代码放入 viewDidLoad:
UIBarButtonItem *addbutton = self.navigationItem.leftBarButtonItem;
[addbutton setTarget:self];
[addbutton setAction:@selector(add)];
并将功能更改为:
- (void)add {
myCustomViewController *add = [[myCustomViewController alloc] initWithNibName:@"myCustomViewController" bundle:nil];
[self presentModalViewController:add animated:YES];
[add release];
}
谢谢你的帮助,帕思!