我正在使用一个UIViewController和许多UIViews创建一个应用程序。我有MainViewController,下面有一个UIView,在加载时显示,MainWindow.xib中还有一些其他的UIViews。如何从一个视图切换到另一个视图?
更新
感谢您的回复。
我已将MainViewController添加到我的appDelegate。
在FinishedLaunching上:[window addSubview:[viewController view]];
View Controller中有一个名为goToNextPage的函数。
-(IBAction)goToNextPage:(id)sender{
[self.view removeFromSuperview];
[self.view addSubview:tableOfContents];
}
在Interface Builder中,我将View Controller添加到MainWindow.xib中。在那个视图控制器下,我有一个UIView(称为Cover),它在启动时加载它的子项,另一个UIView(最终很多)命名为TableOfContents,它本身就是。
我试图在这里发布我的MainWindow.xib图像,但显然我的声誉不够高。
UIView封面上有一个链接到goToNextPage函数的按钮。
当我点击按钮时,页面变为空白,就好像一个视图被成功删除但下一个视图没有被加载。
如何让goToNextPage函数将预装的UIView Cover与另一个名为TableOfContents的UIView切换?
另一个编辑:
BookTest6AppDelegate.h:
#import <UIKit/UIKit.h>
@class MainViewController;
@interface BookTest6AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
IBOutlet MainViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet MainViewController *viewController;
@end
BookTest6AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[window addSubview:[viewController view]];
[window makeKeyAndVisible];
return YES;
}
MainViewController.h
#import <UIKit/UIKit.h>
@class TableOfContents;
@interface MainViewController : UIViewController {
IBOutlet TableOfContents *tableOfContents;
}
@property (nonatomic, retain) IBOutlet TableOfContents *tableOfContents;
-(IBAction)fGoToTableOfContentsController:(id)sender;
-(IBAction)fGoToNextPageController:(id)sender;
@end
MainViewController.m
#import "MainViewController.h"
#import "TableOfContents.h"
@implementation MainViewController
@synthesize tableOfContents;
-(IBAction)fGoToTableOfContentsController:(id)sender{
[self.view removeFromSuperview];
[self.view addSubview:self.tableOfContents];
}
-(IBAction)fGoToNextPageController:(id)sender{
}
我的UIView类基本上只是启动链接到MainViewController.h中定义的函数的按钮。
答案 0 :(得分:2)
首先,您需要知道何时从一个切换到另一个。
然后你说它到你的MainController和addSubView到mainController.view另一个视图。
也许如果你给我们更多的信息或代码,我们可以帮你多一点: - )
祝你好运 文森特编辑:
[self.view removeFromSuperview];
您要删除窗口视图。我认为这不是更好的方式^^尝试
[ viewController.view removeFromSuperview ];: - )
它的效果更好吗?
编辑: 编辑之二:汉,这是我的错。您需要删除控制器并在应用程序委托中添加另一个控制器而不是在您的mainController中(您也可以这样做,但不能使用您的实际代码)。 您有两种选择: 1°)在您的app委托中声明所有控制器。 2°)在一个主控制器中声明所有控制器。但是主控制器将在这里“控制”其他人。