2009-02-24 57 views

回答

2

是的一種可能。只需使用視圖控制器創建一個新視圖並在您的類中創建該視圖的一個實例。然後在ibaction中,你可以做一些刪除和添加子視圖。這只是一個快速簡便的方法壽,你可以進入很多更詳細的你將如何管理每個視圖等上請求

編輯: 在你的類,你會在創建它的一個實例像這樣的接口:

MyClass *myClass; (make sure to alloc and init in the init or awakeFromNib method) 

然後讓應用程序委託的一個實例,在這樣的IBAction爲:

MyAppDelegate *myAppDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; 

然後你就可以做到這一點,切換從一個視圖到另一個:

[self removeFromSuperView]; (or self.view in case this is a view controller) 
[[myAppDelegate window] addSubview:myClass]; 
+0

感謝烏拉圭回合的答案。你能給我一些例子或示例代碼嗎? – Nasir 2009-02-24 10:21:11

1

你可以這樣做以下補充編程一個觀點:

 //If you create controllers via XCode, just link them in the .h file with IBOutlet 
    UIViewController *aViewController = [[UIViewController alloc] initWithNibName:@"YourNibName" bundle:[NSBundle mainBundle]]; 
    self.viewController = aViewController; 
    [aViewController release]; 
    // Add the view controller's view as a subview of the window 
    UIView *controllersView = [viewController view]; 
    [window addSubview:controllersView]; 
    [window makeKeyAndVisible];