如何更改主視圖是基於導航的應用程序! (how to change main view is navigation based app!)


問題描述

如何更改主視圖是基於導航的應用程序! (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 tutorial on how I can accomplish this. Can anyone please point me in the right direction.

Thanks.

‑‑‑‑‑

參考解法

方法 1:

  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.

方法 2:

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.

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.

(by wayneY.RameshRahul Sharma)

參考文件

  1. how to change main view is navigation based app! (CC BY‑SA 3.0/4.0)

#cocoa-touch #iphone #XCode






相關問題

防止 UITableView 在自定義子視圖處理觸摸時滾動 (Prevent UITableView from scrolling when custom subview is handling touches)

NSMutableArray removeObjectAtIndex 在第二次執行時崩潰 (NSMutableArray removeObjectAtIndex crashes on second execution)

Apakah NSURLConnections termasuk dalam model atau pengontrol saya? (Do NSURLConnections belong in my model or controller?)

Lợi ích của việc sử dụng NSString tĩnh cho CellIdentifier là gì? (Whats the advantage of using a static NSString for CellIdentifier?)

CGContextRef 中的坐標係是什麼樣的? (How does the coordinate system in an CGContextRef look like?)

無法在不崩潰的情況下設置 ABPeoplePickerNavigationController 的 addressBook 屬性 (Can't set the addressBook property of ABPeoplePickerNavigationController without crashing)

tableViewHeader 拒絕多個子視圖 (tableViewHeader rejecting multiple sub-views)

界面生成器添加了一個標籤欄按鈕,但未顯示 (Interface builder added one tab bar button, but not showing up)

iVar getter / 方法同名? (iVar getter / method with same name?)

如何更改主視圖是基於導航的應用程序! (how to change main view is navigation based app!)

捕捉返回按鈕導航事件 (Catching back button navigation event)

如何將對象轉發到單獨的子視圖? (How can i forward objects to separate subviews?)







留言討論