开发者

how to change main view is navigation based app!

I'm new to programming and my problem is this.

I have a navigation based app that displays data from a SQLite database in a table when the app launches. I would like to have a different main view and have the table with data display when the user presses a button on a tab menu.

I have been unable to find any info or preferably a 开发者_Python百科tutorial on how I can accomplish this. Can anyone please point me in the right direction.

Thanks.


  1. Create the class which needs to be displayed. Say you created the class named LoginView.

  2. When you create the navigation based application, the AppDelegate class contains the following code:

    // Add the navigation controller's view to the window and display.
    [window addSubview:navigationController.view];
    [window makeKeyAndVisible];
    
  3. Add the following lines just above the code mentioned in step 2:

    LoginView *logView = [[LoginView alloc] initWithNibName:@"LoginView" bundle:nil];
    [self.navigationController pushViewController:(UIViewController *)logView animated:YES]; 
    
  4. Add the following or similar function in the AppDelegate class. This will hide the LoginView view and displays the rootView controller class.

    -(void) LoginSuccess
    {
        // Add the navigation controller's view to the window and display.
    
        [self.navigationController popViewControllerAnimated:YES];
    
        RootViewController *rootView = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
        [self.navigationController pushViewController:(UIViewController *)rootView animated:YES];
    
        [window addSubview:navigationController.view];
        [window makeKeyAndVisible];
    }
    
  5. Add a function in the LoginView class similar to the function mentioned below. Call the function mentioned in step 4 as shown:

    -(IBAction) OpenNavigation
    {
        TestNavgAppDelegate *pApp = [[UIApplication sharedApplication] delegate];
        [pApp LoginSuccess];
    }
    
  6. Add the following code in the RootView controllers viewDidLoad method to hide the back button if you want:

    [super viewDidLoad];
    
    self.navigationItem.backBarButtonItem = NULL;
    self.navigationItem.hidesBackButton = YES;
    

All the best.


All you want is to switch to a Tabbar based application from a Naviagtion based application.

STEP 1] Open MainWindow.xib and Replace navigationcontroller with a UITabbarController STEP 2] In the application delegate replace the variable

UINavigationController *navController;

with

UITabBarController* tabBarController;

i.e

@interface ViewTestAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    UINavigationController *navController;
}

@property (nonatomic, retain) IBOutlet UINavigationController *navController;
@property (nonatomic, retain) IBOutlet UIWindow *window;

with

@interface ViewTestAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    UITabBarController* tabBarController;
}

@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, retain) IBOutlet UIWindow *window;

and accordingly update the same in property as well as in .m file

replace the code

[self.window addSubview:navController.view];

with

  [self.window addSubview:tabBarController.view];

in the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
method.

All we have done is replaced the navigation controller with a tabbar controller.

how to change main view is navigation based app!

how to change main view is navigation based app!

After you connect the appropriate outlets all you need to do is to assign desired view controller (you can reuse the view you were using earlier to show data from Sqlite database) as the selected view controller for TabbarController which will be the first view loaded with a tableview.

this will all look as follows.

how to change main view is navigation based app!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜