使用UIActivityIndi​​catorView加载资源然后调用另一个ViewController的启动画面

时间:2012-09-27 01:47:10

标签: iphone objective-c ios xcode cocoa

我正在努力做一些简单的事情,

我有一个viewcontroller,我想用作主菜单viewcontroller的启动画面。我无法理解为什么没有从模型中调用模态。

任何人都知道发生了什么事?

- (void)viewDidLoad
{
    [super viewDidLoad];


    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    indicator.frame = CGRectMake(0.0, 0.0, 180.0, 180.0);
    indicator.center = self.view.center;    
    [self.view addSubview:indicator];
    [indicator bringSubviewToFront:self.view];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = TRUE;

    //prepare all resources for app

    [indicator startAnimating];

    UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
    MainMenuViewController* mainMenu = [sb instantiateViewControllerWithIdentifier:@"mainMenu"];

    mainMenu.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:mainMenu animated:YES];
}

如果我使用相同的代码附加按钮按下事件,它可以正常工作:

//[btn1 addTarget:self action:@selector(buttonPressedAction:) forControlEvents:UIControlEventTouchUpInside];

- (void)buttonPressedAction:(id)sender
{


    UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
    MainMenuViewController* mainMenu = [sb instantiateViewControllerWithIdentifier:@"mainMenu"];

    mainMenu.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:mainMenu animated:YES];

}

1 个答案:

答案 0 :(得分:0)

我将viewDidLoad更改为viewDidAppear并且工作正常。我不知道为什么呢