2009-02-24 23 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];