0
我想從MainWindow.xib文件中的bar按鈕顯示ModalViewController。我將如何做到這一點?我期待使用的基本代碼是這樣的:使用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];
}
感謝您的幫助,PARTH!
它實際上是一個導航控制器上的Bar按鈕,它有什麼區別嗎?它在編譯時顯示在視圖上,我只是不知道如何在點擊時顯示modalviewcontroller。 – 2011-03-16 09:25:43
@Simon:你是通過編碼還是通過XIB創建按鈕? – 2011-03-16 09:39:37
你可以把你的方法'add'加入到你的AppDelegate.m文件中。 – 2011-03-16 09:45:22