【问题标题】:How to move one viewcontroller to another viewcontroller after loading progressbar in ios在ios中加载进度条后如何将一个视图控制器移动到另一个视图控制器
【发布时间】:2015-10-15 11:18:56
【问题描述】:

您好,我是 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];

}

【问题讨论】:

  • 你把重复 = YES。所以计时器总是一次又一次地触发。如果您想停止该计时器并移动到下一个视图控制器,那么您必须设置一些条件。就像,计时器应该在一段时间后停止,因此您需要使计时器无效,并且在无效之后您必须推送另一个视图控制器。

标签: ios objective-c progress-bar


【解决方案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];
    }
}

【讨论】:

    【解决方案2】:

    更新此方法:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-06
      • 1970-01-01
      • 2017-09-17
      • 2023-03-11
      • 1970-01-01
      相关资源
      最近更新 更多