iOS - 使用父视图控制器即时显示子视图控制器

时间:2013-04-14 23:00:37

标签: ios view uiviewcontroller childviewcontroller

我将在按钮单击时显示动态视图控制器的多个视图控制器,以下是我的视图控制器的布局方式: enter image description here

在按下“开始”按钮之前,“calculationView”视图不会显示任何内容。 当用户按下“开始”按钮时,视图控制器2中的“calculateView”显示子视图控制器(此处未显示)。

View Controller 2中的后退箭头将用户带回标签栏中的第1项,并在计算视图中的VIew Controller 2中显示相同的视图控制器。

现在,一切正常,但视图控制器1中的computeView中的内容在视图显示后约一秒出现。

以下是我在View Controller 2中加载calculateView的方法:

- (IBAction)startRunning:(id)sender {
    NSLog(@"Start button pressed.");

    helper = [[RunsDataHelper helper] init];

    // Set this value to true so then other views also display the calculationsView
    [helper setRunInProgres:YES];

    // Add Calculations View Controller
    CalculationViewController *calculationController = [self.storyboard instantiateViewControllerWithIdentifier:@"Calculate"];
    [self addChildViewController:calculationController];
    calculationController.view.frame = self.calculationView.bounds;
    [UIView transitionWithView:self.calculationView
                      duration:0.4
                       options:UIViewAnimationOptionTransitionCurlDown
                    animations:^{
                        [self.calculationView addSubview:calculationController.view];
                    }
                    completion:nil];
    [calculationController didMoveToParentViewController:self];

}

以下是我使用runInProgress BOOL在View Controller 1中显示calculateView的方法:

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    helper = [[RunsDataHelper helper] init];
    if([helper runInProgres] == YES)
    {

        //Add Calculations View Controller
        CalculationViewController *calculationController = [self.storyboard instantiateViewControllerWithIdentifier:@"Calculate"];
        [self addChildViewController:calculationController];
        calculationController.view.frame = self.calculationView.bounds;
        [self.calculationView addSubview:calculationController.view];
        [calculationController didMoveToParentViewController:self];
    }

}

问题:
现在我的问题是如何才能使它与计算控制器1同时出现计算视图。

另外,我有一个设计问题。 calculateView将位于每个View Controller的静态位置。有没有更好的方法在每个视图控制器上显示基于runInProgress BOOL的computeView。

0 个答案:

没有答案
相关问题