I have an UIViewController
which has a UITableView
inside. In this view controller I want to display some data that I have downloaded from the internet
Your code:
OfficesViewController *ovc = [[OfficesViewController alloc] init];
Creates new instance property of OfficesViewController
. Since it's a new instance it does not have a connection to the OfficesViewController
you triggered after downloading and parsing process. To be able to comunicate b/w OfficesViewController
and OfficesParser
create a modified init method for OfficesParser
that allows week pointer to the OfficesViewController
.
@interface OfficesParser ()
@property(nonatomic,assign)OfficesViewController *ovc;
@end
@implementation OfficesParser
@synthesize ovc;
-(id)initWithDelegate:(OfficesViewController*)delegate{
ovc = delegate;
return [self init];
}
Now you can access your ovc delegate.
- (void)queueFinished:(ASINetworkQueue *)queue {
NSArray *offices = [self offices];
[ovc setOffices:offices];
}
Finally create your OfficesParser like that
self.officesParser = [[OfficesParser alloc] initWithDelegate: self];
You need to take a look at delegates and protocols. They're exactly what you're looking for, as they let classes communicate without having to persist a reference. Here is another explanation on them.