views:

170

answers:

6

Hi, I am having a problem with accessing public variable 'activity', which is a UIActivityIndicatorView type, see class declaration below in QuickStartViewController.h:

@interface QuickStartViewController : UIViewController <ABPeoplePickerNavigationControllerDelegate> {
@public
IBOutlet UIActivityIndicatorView *activity;

}

@property (nonatomic, retain) UIActivityIndicatorView *activity;

@end

The function is called from another class:

#import "QuickStartViewController.h"
@interface NumberValidator : QuickStartViewController....

See below:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[activity startAnimating];
NSLog(@"This function is called, but [activity startAnimating] still doesn't work...");
}

Note: [activity startAnimating] works fine when called within the QuickStartViewController class

Do you have any suggestions as to why [activity startAnimating] is not working?

A: 

I would start by setting a breakpoint in -connectionDidFinishLoading: and verifying that activity is not nil.

Costique
A: 

This probably works - i.e. the activity indicator starts animating. There may be another problem, though - the GUI is not refreshed until you stop processing the connectionDidFinishLoading method, and therefore it seems that [activity startAnimating] doesn't work. (You can test this by not calling [activity stopAnimating] - it should show up eventually.)

See e.g. this thread (connectionDidFinishLoading - how to force update UIView?) and my response.

Adam Woś
Hi adam,I have tried this - with no luck :(Kind regards,Mitul
Mitul Ruparelia
A: 

Is it (a) not compiling, (b) crashing when it hits there, or (c) just not doing anything? My suspicion is that it's (c), and it's because you don't have an activity indicator there. Try logging the value of activity to the console, and verify its a valid object.

Ben Gottlieb
A: 

Hi both,

Thanks for the quick responses.

The connectionDidFinishLoading does successfully execute, and I have placed NSLogs to confirm. However, the startAnimating doesn't.

Note:

If I do [activity startAnimating]; within the following then it works...:

QuickStartViewController.m (not NumberValidator.m):

- (IBAction)showPicker:(id)sender {
[activity startAnimating];
...
}
Mitul Ruparelia
Is `activity` nil in the `connectionDidFinishLoading`? Have you tested my suggestion to not turn it off and wait if it appears when you finish processing the URL response?
Adam Woś
A: 

I have carried out various tests, and I can confirm that activity returns nil

How can I fix this?

Mitul Ruparelia
+1  A: 

The IBOutlet macro indicates that the UIActivityIndicatorView will be constructed and assigned when an instance of QuickStartViewController or NumberValidator are instantiated via NSBundle's +loadNibNamed:owner:options: or calling UIViewController's initWithNibName:bundle:

If you are not instantiating your NumberValidator via it's nib, then the activity property will not be assigned. If you are constructing it via a nib, then you have not assigned the outlet with an appropriate UIActivityIndicatorView in Interface Builder, by CTRL+Dragging your UIActivityIndicatorView to your controller.

Stuart Carnie