【问题标题】:ViewDid appear not working xcodeViewDid 似乎无法正常工作 xcode
【发布时间】:2011-03-22 06:23:23
【问题描述】:

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

- (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]);
    }

}

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

    试试这个:

    首先在您的 Tabbar 控制器 .m 文件上使用以下函数:

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

    并且在 Tabbar 控制器 .m 文件的“viewDidLoad”函数中,使用 "localNavigationController.delegate = self;",如下面的示例所示。

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

    希望它对你有用。

    【讨论】:

    • 海,谢谢你的回答。其实我试过这个。这仅适用于我的客户选项卡,但在这里我正在客户中创建其他 3 个 uiview 控制器。 t
    • 你必须使用“localNavigationController.delegate = self;”分别针对所有视图控制器
    猜你喜欢
    • 2017-09-04
    • 2012-05-06
    • 2013-02-17
    • 2017-10-09
    • 2017-08-03
    • 2014-05-02
    • 2011-09-11
    • 2016-02-11
    • 1970-01-01
    相关资源
    最近更新 更多