将 UITabBarController 从单独的 XIB 加载到 iPhone 上的 Window 应用程序中

发布于 2024-10-09 19:35:19 字数 1406 浏览 2 评论 0原文

我正在努力制作我编写的 Android 应用程序的 iPhone 版本(所以请耐心等待)。该应用程序有一个主要显示 Web 视图的主视图和一些控制 Web 视图的其他控件。我已经让应用程序的这一部分在 UIWindow 上运行。

应用程序的另一部分是“个人资料”页面,允许用户在表单中输入一些个人资料信息。由于选项数量众多,我使用 UITabBarController 将事物接口放在单独的 XIB 中,以将所有内容组合在一起。我已经为应用程序的这一部分提供了一个委托类,以便我可以对视图中的表单字段进行操作。

当应用程序启动时,它应该在第一次运行时向用户显示“个人资料”视图,然后当用户在应用程序中选择“个人资料”时显示个人资料视图。

我遇到的问题是,我似乎找不到一个好的示例(或很好地理解)如何使应用程序加载视图及其委托。如果这是在 Android 下,我将继承 Activity 并让它加载适当的接口文件。

到目前为止,我有一个视图控制器:

@implementation customizeViewController  
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {  
        if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {  
            // Custom initialization  
        }  
        return self;  
    }  
    - (void)dealloc {  
        [super dealloc];  
    }  
@end

在应用程序委托标头中,我有一个用于保存“个人资料”视图的设置:

UIView *CustomizeWindow;

didFinishLaunchingWithOptions 中,我有以下内容:

CustomizeWindow = [[customizeViewController alloc] initWithNibName:@"CustomizeWindow" bundle:[NSBundle mainBundle]];  
[window makeKeyAndVisible];

...其中 CustomizeWindow 是“配置文件”视图文件的文件名。

我尝试了几种不同的方式来显示它,例如将其作为子视图添加到窗口和 presentModalViewController 中,但没有成功。我怀疑我遗漏了这个难题的一部分,所以任何帮助将不胜感激。

I'm working on making an iPhone version of an Android app that I've written (so please bear with me). The application has a main view that basically displays a web view and some other controls that control the webview. I already have this part of the application working atop a UIWindow.

The other part of the application is a 'profile' page that lets the user enter some profile information into a form. Due to the sheer number of options, I put together thing interface in a separate XIB using a UITabBarController to hold everything together. I already have a delegate class for this part of the application so that I can operate on the form fields in the view(s).

When the app starts, it's supposed to display the 'profile' view to the user on first run and then later display the profile view when the user selects 'profile' in he app.

The problem I'm running into is that I cannot seem to find a good example (or have a good understanding of) how to cause the app to load the view and it's delegate. If this were under Android, I would subclass Activity and have it load the appropriate interface file.

Thus far I have a view controller:

@implementation customizeViewController  
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {  
        if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {  
            // Custom initialization  
        }  
        return self;  
    }  
    - (void)dealloc {  
        [super dealloc];  
    }  
@end

And inside the application delegate header I have this setup for holding my 'profile' view:

UIView *CustomizeWindow;

Within didFinishLaunchingWithOptions I have the following:

CustomizeWindow = [[customizeViewController alloc] initWithNibName:@"CustomizeWindow" bundle:[NSBundle mainBundle]];  
[window makeKeyAndVisible];

...where CustomizeWindow is the filename of the 'profile' view's file.

I have tried a few different ways of displaying this, such as adding it as a sub view to the window and presentModalViewController with no success. I suspect there is a piece to this puzzle that I'm missing, so any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在你怀里撒娇 2024-10-16 19:35:19

从我能读到的所有内容来看,没有办法真正做到这一点。解决方案是扔掉所有东西并使其变得更简单。在本例中,自定义视图控制器使用 UIScrollView 来包含其他视图,然后以编程方式加载其他 xib 文件。

类似于:
<代码>
NSArray *pages = [[NSBundle mainBundle] loadNibNamed:@"CustomizePage1" 所有者:self 选项:nil];
UIView *page1 = [页面objectAtIndex:0];
[page1 setBounds:CGRectMake(0, -20, page1.frame.size.width, page1.frame.size.height)];
[self.scroller addSubview:page1];

并对要加载到滚动视图中的每个 xib 执行上述操作

From everything I could read, there is no way to really do this. The solution was to throw everything out and make it simpler. In this case, a custom view controller using a UIScrollView to contain the other views and then load the other xib files programmatically.

Soemthing like:

NSArray *pages = [[NSBundle mainBundle] loadNibNamed:@"CustomizePage1" owner:self options:nil];
UIView *page1 = [pages objectAtIndex:0];
[page1 setBounds:CGRectMake(0, -20, page1.frame.size.width, page1.frame.size.height)];
[self.scroller addSubview:page1];

And do the above for every xib you want to load into the scroll view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文