如何在ios中加载进度条后将一个viewcontroller移动到另一个viewcontroller

时间:2015-10-15 11:18:56

标签: ios objective-c progress-bar

您好,我是iOS项目的初学者,我正在使用进度条

这里我的主要要求我想要在完成进度条加载后最多5秒加载进度条我想移动另一个视图控制器为此我使用了一些代码但是没有工作请帮帮我

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
    self.progressView.center = self.view.center;
    [self.view addSubview:self.progressView];

  self.myTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(updateUI:) userInfo:nil repeats:YES];


}

- (void)updateUI:(NSTimer *)timer
{
self.progressView.progress += 0.5;

    ContactVC*VC = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactVC"];
    [self.navigationController pushViewController:VC animated:YES];

}

2 个答案:

答案 0 :(得分:1)

- (void)viewDidLoad {
    [super viewDidLoad];

    progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
    progressView.center = self.view.center;
    [self.view addSubview:progressView];

   myTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(updateUI:) userInfo:nil repeats:YES];
}

- (void)updateUI:(NSTimer *)timer
{
    progressView.progress += 0.5/10;

    if ((int)progressView.progress) {

        [myTimer invalidate];

    Demoview*VC = [self.storyboard instantiateViewControllerWithIdentifier:@"Demoview"];
    [self.navigationController pushViewController:VC animated:YES];
    }
}

答案 1 :(得分:0)

更新此方法:

- (void)updateUI:(NSTimer *)timer
{
    self.progressView.progress += 0.5/100;//because this limit is [0-1]. So, you have divide each progress unit by 100 in order to show percentage progress. 
    NSLog(@"%f",self.progressView.progress);
     if ((int)self.progressView.progress) {
       NSLog(@"Call View");
       [self.myTimer invalidate];
       self.myTimer = nil;//so that timer not fire again
       ContactVC *VC = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactVC"];
      [self.navigationController pushViewController:VC animated:YES];
}
}