0

I am trying to get my first spinner to work, and I can't seem to get it to show up on the screen.

I tried dragging the UIActivityIndicatorView on the storyboard to my screen, but then when I tried to connect it to my header file via the storyboard, it didn't seem to respond. (what are the correct steps there?)

So I did it manually. I added this line to my .h file:

@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *aSpinner;

and then I added these lines to my .m file

UIActivityIndicatorView   *aSpinner; 

//throw up spinner from submit btn we created
aSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:
            UIActivityIndicatorViewStyleWhiteLarge];

[self.view addSubview:aSpinner]; 
[aSpinner startAnimating]; 

but when I ran the test, no spinner showed up. Any thoughts on what I am doing incorrectly here?

dandan78
  • 13,328
  • 13
  • 64
  • 78
GeekedOut
  • 16,905
  • 37
  • 107
  • 185
  • Did you test if your code hits the part with the spinner? – i-- Aug 09 '12 at 13:24
  • @therao yes I did. I put that code right in the - (void)viewDidAppear:(BOOL)animated – GeekedOut Aug 09 '12 at 13:27
  • Well actually if I drag the UI element right from the right side of the screen to the storyboard screen, the spinner does appear, but I am not sure how to connect it to the code so I can make it spin and appear/disappear – GeekedOut Aug 09 '12 at 13:28
  • you need to set it up as outlet, easier to watch a simple youtube tutorial on connecting outlets than explaining. Then once it is connected you could call same methods on it like you currently do, i.e. [aSpinner startAnimating], stopAnimating, etc – i-- Aug 09 '12 at 13:31
  • Actually I see here that they don't even mention the spinner in the header file http://agilewarrior.wordpress.com/2012/04/03/how-to-display-uiactivityindicatorview-spinner-for-long-running-operations/ – GeekedOut Aug 09 '12 at 13:42

2 Answers2

1

Select your spinner in your nib file right click -> click & drag from reference to files owner. Then select aSpinner.

It does not show up, because activityindicator in nib and your code are not connected.

rustyMagnet
  • 3,479
  • 1
  • 31
  • 41
Mert
  • 6,025
  • 3
  • 21
  • 33
  • yeah I think connecting the spinner to the code is where my problem lies. I can't see to control+drag it to the header. Do you know how to correctly connect it and make it an outlet? Thanks! – GeekedOut Aug 09 '12 at 13:35
  • I edited my answer and added a link. You can find there how to do that with screenshots. – Mert Aug 09 '12 at 13:57
0

You should use "strong" instead "weak" in the @property line.

The UIActivityIndicatorView is freed directly if weak is used and you don't want that.

Maybe you should set a frame to the view as well.

JKvr
  • 650
  • 7
  • 15