关于iPhone:ViewDid出现无法正常工作的Xcode

ViewDid appear not working xcode

海,
我创建了一个基于选项卡的iRestaura项目。我使用5个标签栏项目。标签栏名称之一是客户。当我点击客户时,将以编程方式使用3个viewcontroller创建另一个选项卡。当我使用视图didload方法时,tabbarcontroller创建成功。但是,当我使用视图didAppear时,则不会创建选项卡控制器。在这两种情况下,以编程方式创建的其他三个viewcontroller,都没有出现视图不起作用。但是所有情况下我都需要使用viewDidAppear方法。
请任何人都可以帮助我...
在下面给出了不起作用的viewDidAppear方法.....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    UITabBarController *tabBarController1=[[UITabBarController alloc] init];

    CustomerListViewController *customerListViewController=[[CustomerListViewController alloc] init];
    customerListViewController.title=@"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];  
    selectedCustomerViewController.title=@"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];
    invoiceListViewController.title=@"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]);
    }

}

尝试一下:

首先在Tabbar控制器.m文件上使用以下功能:

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

并在Tabbar控制器.m文件的" viewDidLoad"功能中,使用" localNavigationController.delegate = self;"。如以下给定示例中所使用。

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

希望它对您有用。