2009-02-20 21 views
2

我正在爲iPhone開發基於Window的應用程序。我使用Interface Builder來構建Interface。我想用Button Action調用一個新屏幕。我如何使用Button動作調用屏幕?如何使用按鈕動作(xcode)調用屏幕?

+0

我不明白他爲什麼被低估。我希望人們能夠解釋爲什麼他們在這樣做時會倒票。反饋是一件好事。 – 2012-10-15 06:29:59

回答

1

通過推動新的控制器到窗口的堆棧的頂部。例如:

EnterNameController *newEnterNameController = [[EnterNameController alloc] initWithNibName:@"EnterName" bundle:[NSBundle mainBundle]]; 
[[self navigationController] pushViewController:newEnterNameController animated:YES]; 
+0

它在基於導航的應用程序中工作。但它不適用於基於Window的應用程序。 – Nasir 2009-02-20 09:47:05

1

蘋果有非凡的金額示例代碼,而這個問題(以及許多其他人)可以很容易地通過簡單地訪問蘋果的iPhone開發站點來解決。 iPhone Dev Site

1

如果您使用的是導航控制器,請按照alamodey的建議將其推到導航控制器的堆棧上。

如果你希望它是一個模態控制器(即,從底部向上滑動並覆蓋前一個控制器的觀點,就像在Safari書籤屏幕),目前它作爲一個模式視圖控制器:

[self presentModalViewController:myNewController animated:YES]; 

當你想將舊控制器背面,解僱模態視圖控制器。從模態視圖控制器內:

[self.parentViewController dismissModalViewControllerAnimated:YES]; 

如果你不想做任何,只是從窗口中刪除當前控制器的視圖,並添加新的控制器:

UIView * containingView = self.view.superview; 
[self.view removeFromSuperview]; 
[containingView addSubview:myNewController.view]; 

如果你走這條路線,你可能想看看+ [UIView beginAnimations:context:],+ [UIView setAnimationTransition:onView:]和+ [UIView commitAnimations](如果我記得方法名稱正確 - 檢查文檔)以動畫過渡。您幾乎總是應該在iPhone OS的屏幕之間切換動畫。

0

你只需要在Xcode幫助下載示例應用程序。嘗試Elements和UIcatalog。還有其他 - 型 'pushViewController' 或 'addSubview' ADN「makeKeyAndVisible的幫助和下載樣品中

1

(在.M類工作)

#import "classtocall.h" 
- (IBAction)ButtonPressed:(id)sender 
{ 
classtocall *mvc = [[classtocall alloc]initWithNibName:@"classtocall" bundle:nil]; 
[self presentModalViewController:mvc animated:NO]; 
} 

(基於窗口的應用程序) 定義英寸h class

- (IBAction)ButtonPressed:(id)sender; 

其中「classtocall」是您要調用的類。

0
nextscreenViewController *login = [[self storyboard] instantiateViewControllerWithIdentifier:@"nextscreenidentifier"]; 

nextscreenidentifier.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 

[self presentModalViewController: nextscreenidentifier animated: YES]; 
相關問題