簡體   English   中英

iOS標簽欄不顯示模態視圖

[英]iOS tab bar not show modal view

我想在應用程序的開頭顯示模態視圖,但它不會出現。 這是我的代碼:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self initDataBase];
    CustomerModel *customer = [[[CustomerPersistor alloc] init] getLoggedCustomer];

    self.window.rootViewController = self.tabBarController;

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.

    UIViewController *profileViewController = [[[ProfileViewController alloc] initWithNibName:@"ProfileViewController" bundle:nil] autorelease];
    profileViewController.title = @"Profile";
    UINavigationController *profileNavigation = [[[UINavigationController alloc] initWithRootViewController:profileViewController] autorelease];

    self.tabBarController = [[[UITabBarController alloc] init] autorelease];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:profileNavigation,  nil];
    self.window.rootViewController = self.tabBarController;

    [self.window makeKeyAndVisible];

    if(customer == nil) { NSLog(@"HO");
        ViewController *login = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    //login.delegate = self.tabBarController.view;

        [self.viewController presentModalViewController:[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]  animated:YES];
    }
    return YES;

}

我該如何解決?

首先,似乎沒有設置的self.viewController屬性,並且您實例化了兩次相同的“ViewController”。 這都是錯的:

ViewController *login = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 
//login.delegate = self.tabBarController.view;
[self.viewController presentModalViewController:[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]  animated:YES]; 

嘗試將此代碼移動到profileViewController的viewDidLoad ...即讓TabBarController加載其第一個選項卡的視圖控制器。

從模型視圖中啟動一個instanse,如下所示:

modelView = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];

請按照以下列表:

  1. 設置viewController模型呈現的樣式

     [modelView setModalPresentationStyle:UIModalPresentationPageSheet]; 
  2. 然后使用:

     [self.viewController presentModalViewController:floorView animated:YES]; 
  3. 然后,設置模型控制器的大小和位置,如下所示:

     modelView.view.superview.bounds = CGRectMake(0, 0, 700, 550);//it's important to do this after presentModalViewController modelView.view.superview.center = self.view.superview.center;//self.view assumes the base view is doing the launching, if not you might need self.view.superview.center etc. 

希望這對你有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM