1

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?

5 Answers 5

1

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.

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

Comments

0

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

Comments

0

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.

1 Comment

Hi adam, I have tried this - with no luck :( Kind regards, Mitul
0

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.

Comments

0

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

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.