问题
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?
回答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.
You can find it here with screenshots how to do that
https://developer.apple.com/library/ios/#documentation/IDEs/Conceptual/xcode_quick_start/020-Tutorial_Designing_a_User_Interface_with_Interface_Builder/interface_builder_tutorial.html#//apple_ref/doc/uid/TP40010575-CH3-SW3
回答2:
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.
来源:https://stackoverflow.com/questions/11884423/uiactivityindicatorview-spinner-not-showing-up