Domanda

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.

any advise would be apprecaited. I have had limited success thus far with my previous posts.

Thank you,

Silver Tiger

È stato utile?

Soluzione

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 ..

Altri suggerimenti

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

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

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),

UINavigationController *nodes = [[NodeNavigationController alloc] initWithNibName:@"NodeNavigationController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:modems, nodes, home,viewController1, viewController2, nil];

Lastly, in your UINavigationController's init method (or similar)

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

you need to add this...

Nodes *viewController = [[Nodes alloc] initWithNibName:@"Nodes" bundle:[NSBundle mainBundle]];
    self.viewControllers = [NSArray arrayWithObjects:viewController, nil];

Now in the "Nodes" viewController you can use the usual "[...pushViewController:...]" stuff you've always used.

example...

[self.navigationController pushViewController:viewController animated:YES];

I hope this was helpful.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top