2011-03-22 64 views
0

Hai, 我已經創建了一個基於標籤的iRestaura項目。我使用5個標籤欄項目。其中一個tabbar名稱是Customer。當我點擊客戶另一個標籤欄是用3 viewcontroller編程創建的。當我使用視圖的didload方法tabbarcontroller創建成功。但是,當我使用視圖didAppear然後tabbar控制器不會創建tabbar。在這兩種情況下,其他三個視圖控制器是以編程方式創建的,沒有視圖確實沒有工作。但所有的情況下,我需要使用viewDidAppear方法。 PLZ誰能幫我... 的viewDidAppear方法,它不工作給予波紋管.....ViewDid似乎不工作xcode

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
    UITabBarController *tabBarController1=[[UITabBarController alloc] init]; 

    CustomerListViewController *customerListViewController=[[CustomerListViewController alloc] init]; 
    [email protected]"Customer List"; 
    UIImage *anImage1 = [UIImage imageNamed:@"customer.png"]; 
    UITabBarItem *theItem1 = [[UITabBarItem alloc] initWithTitle:@"CustomerList" image:anImage1 tag:0]; 
    customerListViewController.tabBarItem = theItem1; 


    SelectedCustomerViewController *selectedCustomerViewController= [[SelectedCustomerViewController alloc] init]; 
    [email protected]"Selected Customer"; 
    UIImage *anImage3 = [UIImage imageNamed:@"selectedCustomer.png"]; 
    UITabBarItem *theItem = [[UITabBarItem alloc] initWithTitle:@"Selected Customer" image:anImage3 tag:1]; 
    selectedCustomerViewController.tabBarItem = theItem; 

    InvoiceListViewController *invoiceListViewController=[[InvoiceListViewController alloc] init]; 
    [email protected]"Invoice List"; 
    UIImage *anImage2 = [UIImage imageNamed:@"invoiceNo.png"]; 
    UITabBarItem *theItem2 = [[UITabBarItem alloc] initWithTitle:@"Invoice List" image:anImage2 tag:2]; 
    invoiceListViewController.tabBarItem = theItem2; 

    NSMutableArray *controllers=[[NSMutableArray alloc] init]; 
    [controllers addObject:customerListViewController]; 
    // [controllers1 addObject:vc1]; 
    [controllers addObject:selectedCustomerViewController]; 

    [controllers addObject:invoiceListViewController]; 
    ///[controllers1 addObject:vc4]; 
    tabBarController1.viewControllers=controllers; 

    [self.navigationController setNavigationBarHidden:YES animated:YES]; 
    [[self view] addSubview:tabBarController1.view]; 
    for (int t=0; t<[controllers count]; t++) 
    { 
     NSLog(@"controller%@",[controllers objectAtIndex:t]); 
    } 

} 

回答

0

試試這個:

首先使用下面的功能時,您的TabBar控制器.m文件上:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated 
{ 
    [viewController viewWillAppear:YES]; 
} 

而且在控制器的TabBar .m文件的你 「的viewDidLoad」 功能,使用「localNavigationController.delegate =自我;」在以下給出的例子中使用。

UserListing *nearBy = [[UserListing alloc] init]; 
nearBy.tabBarItem.image = [UIImage imageNamed:@"icoTabNearby.png"]; 
nearBy.tabBarItem.title = @"Nearby"; 
localNavigationController = [[UINavigationController alloc] initWithRootViewController:nearBy]; 
localNavigationController.delegate = self; 

希望它適合你。

+0

海,謝謝你的回答。其實我已經試過了。這隻適用於我的客戶選項卡,但在這裏我正在爲客戶創建其他3個uiview控制器。 t – 2011-03-23 06:41:48

+0

你必須使用「localNavigationController.delegate = self;」爲所有viewcontrollers單獨 – Prabh 2011-03-23 09:28:29