2012-08-31 22 views

回答

1

在viewDidLoad方法創建yourButton如下方式...

UIButton *yourButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[yourButton setTitle:@"YearButton" forState:UIControlStateNormal]; 
yourButton.frame = CGRectMake(240, 40, 75, 30);  
[yourButton addTarget:self action:@selector(buttonSelected:) forControlEvents:UIControlEventTouchUpInside]; 
[self.view addSubview:yourButton]; 

這是您的方法代碼和createViewController是CreateViewCont的對象滾筒類和它在.h文件中聲明.....

-(void) buttonSelected:(id)sender{ 
    if (!createViewController) { 
       createViewController = [[CreateViewController alloc] initWithNibName:@"CreateViewController" bundle:nil]; 

      } 


      [self.navigationController pushViewController:createViewController animated:YES]; 

} 

我認爲這對您會有所幫助。

+0

你爲什麼要創建的UIBarButtonItem? – AppHandwerker

1

假設你在你的項目中使用UINavigation控制器。

然後爲按鈕動作就叫

[yourUIButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; 

和被調用該方法只需做到以下幾點:

-(void)buttonAction{ 
    [self.navigationController pushViewController:YourViewController animated:YES]; 
} 
相關問題