xcode 4.2 选项卡式应用程序继承
我一直在阅读一些内容,试图找出如何为我的应用程序创建正确的视图层次结构。我使用 arc 在 xcode 4.2 中创建了一个基本选项卡式应用程序,但这个新应用程序不包含 mainwindow.xib,因此许多使用 IB 的教程对我来说毫无用处。我有一个 5 个选项卡的应用程序已经在工作,并且该应用程序的“基础”按预期工作。我需要的是在当前正在查看的特定“选项卡式”窗口中合并更多视图。我的继承体系很简单,如下所示。我的猜测带有问号,因为我只有 5 个基本类别,目前所有 UIViewController 都在 tabBarController
应用程序层次结构中(提议),
Home (Currently UIViewController using homeViewController, convert to UINavigationController?)
Add (UIViewController with HomeAdd.xib?)
Edit (UIViewController with HomeEdit.xib
delete (UIViewController with HomeDelete.xib?)
ViewList - Single page to view list (Currently UIViewController using viewListViewController)
Share - Single page to send emails / invites (Currently UIViewController using shareViewController)
Friends (UINavigationController with root view of FriendsRoot.xib?)
Add (UIViewController with FriendsAdd.xib?)
Edit (UIViewController with FriendsEdit.xib?)
delete (UIViewController with FriendsDelete.xib?)
Settings - Single page for app settings/preferences (Currently UIViewController using settingsViewController)
我什至不确定上述层次结构是否可能(即在 tabBarController 中混合视图控制器),并且会喜欢关于如何以编程方式完成此操作的输入,因为这似乎是我在应用程序委托中的唯一选择,因为默认情况下没有 mainwondiw.h/m/xib 。
我的应用程序委托中当前的代码如下:
AppDelegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tabBarController;
@end
AppDelegate.m
@synthesize window = _window;
@synthesize tabBarController = _tabBarController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *homeViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
UIViewController *viewListViewController = [[ViewListViewController alloc] initWithNibName:@"ViewListViewController" bundle:nil];
UIViewController *shareViewController = [[ShareViewController alloc] initWithNibName:@"ShareViewController" bundle:nil];
UIViewController *friendsViewController = [[FriendsViewController alloc] initWithNibName:@"FriendsViewController" bundle:nil];
UIViewController *settingsViewController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
[self.tabBarController setDelegate:self];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:homeViewController, viewListViewController, shareViewController, friendsViewController, settingsViewController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
我已经尝试了几次注入 UINavigationControllers 或使用自定义按钮替换视图的尝试,但所有这些似乎都会导致构建失败,因为我仍在学习上下文和代码。
I have been reading up a bit I am trying to figure out how to create a proper view herarchy for my app. I created a base Tabbed application in xcode 4.2 using arc, but this new app does not include a mainwindow.xib, so many of the tutorials that use IB are uesless to me. I have a 5 tab application working already and the "base" of the app works as expected. What I need is to incorporate more views within a specific "tabbed" window currently being viewed. My heirarchy is simple as seen below. My speculation is added with question marks as I have only the 5 base categories, all currently UIViewControllers within the tabBarController
App heriarchy (proposed)
Home (Currently UIViewController using homeViewController, convert to UINavigationController?)
Add (UIViewController with HomeAdd.xib?)
Edit (UIViewController with HomeEdit.xib
delete (UIViewController with HomeDelete.xib?)
ViewList - Single page to view list (Currently UIViewController using viewListViewController)
Share - Single page to send emails / invites (Currently UIViewController using shareViewController)
Friends (UINavigationController with root view of FriendsRoot.xib?)
Add (UIViewController with FriendsAdd.xib?)
Edit (UIViewController with FriendsEdit.xib?)
delete (UIViewController with FriendsDelete.xib?)
Settings - Single page for app settings/preferences (Currently UIViewController using settingsViewController)
I am not even sure if the above heirarchy is possible (i.e. mixing view controllers within a tabBarController), and would love input as to how to accomplish this programmatically as this appears to be my only option within the app delegate since there is no mainwondiw.h/m/xib by default.
My current code for this within my app delegate is as follows:
AppDelegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tabBarController;
@end
AppDelegate.m
@synthesize window = _window;
@synthesize tabBarController = _tabBarController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *homeViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
UIViewController *viewListViewController = [[ViewListViewController alloc] initWithNibName:@"ViewListViewController" bundle:nil];
UIViewController *shareViewController = [[ShareViewController alloc] initWithNibName:@"ShareViewController" bundle:nil];
UIViewController *friendsViewController = [[FriendsViewController alloc] initWithNibName:@"FriendsViewController" bundle:nil];
UIViewController *settingsViewController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
[self.tabBarController setDelegate:self];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:homeViewController, viewListViewController, shareViewController, friendsViewController, settingsViewController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
I have tried a few attempts to inject UINavigationControllers, or alternate views with custom buttons but all seem to result in a failed build since I am still learning the context and code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Home(目前UIViewController使用homeViewController,转换为UINavigationController?)
您可以使用 uiviewcontroller for home
进行以下 3 个操作,您可以使用模型视图控制器,也可以添加单独的视图。
添加(带有 HomeAdd.xib 的 UIViewController?)
编辑(带有 HomeEdit.xib 的 UIViewController
删除(带有 HomeDelete.xib 的 UIViewController?)
朋友也有同样的情况..
我不确定为什么你没有找到 mainwindow.xib ..
Home (Currently UIViewController using homeViewController, convert to UINavigationController?)
u can use uiviewcontroller for home
for the below 3 u can use model view controller or u can add separate views .
Add (UIViewController with HomeAdd.xib?)
Edit (UIViewController with HomeEdit.xib
delete (UIViewController with HomeDelete.xib?)
same case for Friends also..
i am not sure about why didnt u find mainwindow.xib ..
坏消息是,由于较新的选项卡应用程序默认情况下没有“MainWindow.xib”,因此您无法遵循许多在线教程。好消息是它仍然很容易实现。
在方法中的 AppDelegate.m 文件中
(设置 tabBarController 的视图控制器的位置,您需要实际添加类型为“UINavigationController”的 ViewController,而不是类型为“UIViewController”的视图控制器(您需要创建这些文件)。
例如(为了缩写起见)我只显示了我的最后一个 UINavigationController 声明),
最后,在 UINavigationController 的 init 方法(或类似方法)中,
您需要添加此...
现在在“Nodes”viewController 中,您可以使用您一直使用的常用“[...pushViewController:...]”内容
...
我希望这对您有所帮助。
The bad news is that since the newer Tab Application doesn't have a "MainWindow.xib" by default, you can't follow a lot of the tutorials online. The good news is that it is still very easy to implement.
In your AppDelegate.m file in the
method (where you set up your tabBarController's view controllers you need to actually add ViewControllers of type "UINavigationController" instead of type "UIViewController" (you need to create these files).
For example (for abbreviation's sake I only showed my last UINavigationController declaration),
Lastly, in your UINavigationController's init method (or similar)
you need to add this...
Now in the "Nodes" viewController you can use the usual "[...pushViewController:...]" stuff you've always used.
example...
I hope this was helpful.