iphone - 在 UIView 中加载不同的 View Controller (就像 Xcode 的 iFrame)

标签 iphone ios xcode uiview uiviewcontroller

我正在使用 Xcode 中的 Storyboard制作我的第一个 iPhone 应用程序,但遇到了困难。我的主屏幕有一个名为 MemberViewController 的 View Controller ,它是主屏幕。这个屏幕有一个 UIView,它比名为 mainContent 的 View Controller 小。

所以基本上,我希望能够在 UIView 中加载不同的 View Controller (都与 UIView 大小相同)。

MemberViewController(主页) -mainContent (UIView)

GetStartedViewController(我想在 UIView 中显示的独立 View Controller ) ProfileViewController(我想在 UIView 中显示的单独 View Controller )

例如,我希望 GetStartedViewController 有一个按钮,我可以按该按钮切换到 ProfileViewController。 View Controller 需要能够在 mainContent UIView 中相互替换。

非常感谢您的帮助。如果有更简单的方法,请告诉我。

最佳答案

我实际上经常使用这种技术。我的根 UIViewController(你称它为 memberController)的典型设置有一个底部有一个 UITabBar 的 View ,然后是另一个 UIView(您称之为 mainContent),其中包含该栏上方的其余空间。

memberController 一直停留在屏幕上。在 mainContent 中,添加一个 UINavigationController 并使用您的第一个内容承载 GetStartedViewController 对其进行初始化。当您想在标签栏上切换标签时,将适当的消息发送到此 UINavigationController, View 将在其中发生变化。

提示:假设你的 UINavigationController 被称为 navController - 你可以通过发送消息 [navController setNavigationBarHidden:TRUE];

编辑:您请求的代码如下所示。这会将导航 Controller 添加到 applicationDidFinishLaunchingWithOptions 方法中的窗口 View 。而不是窗口,只需在 viewDidLoad 中的 View Controller 上执行相同的操作即可。

windownavController 都是属性

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.navController = [[UINavigationController alloc] initWithRootViewController:[YourViewController new]];
[self.navController setNavigationBarHidden:YES];
[self.window addSubview:self.navController.view];
[self.window makeKeyAndVisible];

希望这对您有所帮助!

关于iphone - 在 UIView 中加载不同的 View Controller (就像 Xcode 的 iFrame),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11552413/

相关文章:

objective-c - Objective-C : Anonymous Blocks, 为什么以及何时?

iphone - 在后台运行 NSTimer

iphone - 防止禁用的 UIButton 传播触摸事件

iphone - 以编程方式创建 View 时不会调用 ViewWillAppear/Disappear

ios - 在 iOS 中以编程方式连接蓝牙耳机?

javascript - 使用 Cloud Code javascript 和 iOS Parse SDK 编辑用户

objective-c - 设置背景图像尺寸 IOS

iphone - UIWebView 中的字体显示不正确

ios - 在自定义 View 和 View Controller 之间传递数据

ios - 在一个 UITableViewCell 上隐藏分隔线