views:

178

answers:

2

Hello everyone,

In Erica Sadun's Download Helper, link here, I can put these methods into my classes:

- (void) didReceiveData: (NSData *) theData;
- (void) didReceiveFilename: (NSString *) aName;
- (void) dataDownloadFailed: (NSString *) reason;
- (void) dataDownloadAtPercent: (NSNumber *) aPercent;

these methods obviously refer back to the "DownloadHelper.h" and "DownloadherHelper.m". I want to know if I am able to access properties on the xib view such as textfields, uitableviews, uilabels ... etc in one of these methods. For example:

- (void) didReceiveFilename: (NSString *) aName {
    [label setText:@"hi"];
}

I have tried doing so, but the objects on the xib view won't update. like the given example above. Is there any way to do this?

Thanks,

Kevin

+1  A: 

It should be possible to access/update the properties of any outlets that you have linked from your xib into your controller. Have you verified via the debugger that the didReceiveFilename: message is being sent to your controller, and that label is non-nil when the setText: message is sent to it?

Edit: I communicated with the person that posted this question offline. The problem was not related to the asynchronous downloads. His code was attempting to notify the controller of the view that contained the table view that a download had started, but the message was sent to the wrong controller instance. Fixing this corrected the problem.

Changed from this:

   // code that switched to an existing DownloadViewController omitted...
   // the new download controller that is created here has no views seen by the user!
   DownloadViewController *download = [[DownloadViewController alloc] init];
   [download downloadstart];

To this:

   // code that switched to an existing DownloadViewController omitted...
   // use the existing DownloadViewController instead of creating a new one
   DownloadViewController *download = (DownloadViewController *)[[appDelegate.rootController viewControllers] objectAtIndex:1];
   [download downloadstart];

The downloadstart method is responsible for updating the table view in Kevin's code.

GregInYEG
Yes I have debugged with breakpoints, and they are all positive. Instead of the [label setText:@"hi"]; code I am actually using the following code to make a cell: [data addObject:name]; [self saveData]; [mainTableView reloadData];
Kevin
A: 

UI updates take place on the main thread, you should try

performSelectorOnMainThread:withObject:waitUntilDone:

[label performSelectorOnMainThread:@selector(setText:) 
           withObject:@"hi" waitUntilDone:NO];
Aaron Saunders
You know what I thought that that would be the solution but its still not working. I'm not actually trying to update the label, I'm trying to update the code here: http://stackoverflow.com/questions/3691074/iphone-sdk-nsmutablearray-addobject-sometimes-works ... this is with a UITableView.
Kevin