0

I have a second view in my app that takes about 2-3 seconds to load. How can I create an activity indicator while the view loads?

I know I can do something like this:

UIActivityIndicatorView *activityView=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    activityView.center=self.view.center;

    [activityView startAnimating];

    [self.view addSubview:activityView];

But how do I tell my app to only load the activity view while switching to another view?

5
  • Are you switching to another view controller? Commented Sep 1, 2013 at 22:21
  • How exactly are you loading your second view? In what view are you adding your activity indicator? Commented Sep 1, 2013 at 22:22
  • Yes, I am switching to another view controller with a UIButton. The activity indicator is in view1. Commented Sep 1, 2013 at 22:26
  • How do you change the views? IBAction? Or is a segue linked straight to a button. Commented Sep 1, 2013 at 23:06
  • I am changing views with a segue. Commented Sep 1, 2013 at 23:42

2 Answers 2

2

you can add this indicator in ViewWillAppear and every time that your view appears it must show indicator if it takes 2-3 seconds.

Sign up to request clarification or add additional context in comments.

Comments

1

Use interface builder and create a new activity indicator on your SECOND VIEW.

    - (void) viewDidLoad
{

 [activityView startAnimating]; /// start animating

 [self performSelector:@selector(stopActivityLoad) withObject:self afterDelay:0.8]; /// stop animating after 0.8

}

- (void) stopActivityLoad
{

[activityView stopAnimating]; /// stop animating.

}

4 Comments

So, if I am creating the activity indicator in the second view, do I need to drag the UIActivityIndicatorView onto my second view? I do want to display it in the first view...
you want to display on first view exactly after you press the button which calls the second view? if so, then you add if on first view, drag on top of first view and hide if, then add code for start and stop animantion on your button. then call the method to show you second view on stopActivityLoad method.
Ok, thanks. But how do I add the code to my button? There is no code for my button because I connected the button to my second view using storyboard. Is there a way to do this still?
yep. Just right click on your button and select Touch Up Inside and create a new method/action for it. You will found it on .m file, and there you have to add code for starting animation and stop animation. When animation stops, call second view.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.