我一直在阅读我试图弄清楚如何为我的应用程序创建正确的视图层次结构。我使用 arc 在 xcode 4.2 中创建了一个基本的 Tabbed 应用程序,但是这个新应用程序不包含 mainwindow.xib,所以许多使用 IB 的教程对我来说毫无用处。我已经有一个 5 选项卡应用程序正在运行,并且该应用程序的“基础”按预期工作。我需要的是在当前正在查看的特定“选项卡式”窗口中合并更多视图。我的层次结构很简单,如下所示。我的猜测添加了问号,因为我只有 5 个基本类别,所有当前 UIViewControllers 都在 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,或使用自定义按钮替换视图,但似乎都导致构建失败,因为我仍在学习上下文和代码。
任何建议都会受到赞赏。到目前为止,我以前的帖子取得的成功有限。
谢谢,
银虎