Hi all,
I am having trouble getting my UITableViewController to reload/refresh the data.
I have a method which uses ASIHTTPRequest to call a URL and bring back some string data. I am trying to put this data into a cell of the table, but [self.tableview reloadData] is not working.
I was thinking that the ASIHTTPRequest completes its tasks on a separate thread, so I tried:
[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
which also did nothing.
How can I reload the data? I have been stuck on this for some time now.
Code: MainViewController.h
#import <UIKit/UIKit.h>
@class ProductClass;
@interface MainViewController : UITableViewController {
ProductClass *item;
}
@property (nonatomic, retain) ProductClass *item;
@end
MainViewController.m
#import "MainViewController.h"
#import "ASIHTTPRequest.h"
#import "ProductClass.h"
@implementation MainViewController
@synthesize item;
- (void) viewDidLoad {
self.title = @"TableView Test";
self.tableView.allowsSelection = NO;
self.item = [[ProductClass alloc] init];
[self callURL];
}
-(void)callURL {
NSURL *url = [NSURL URLWithString:@"http://urlgoeshere.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request {
//Grab the response
NSString *responseString = [request responseString];
//Put the result into the ProductClass item
item.titleOfProduct = responseString;
//This line shows that self.tableview does NOT have an address of 0x0
NSLog(@"%@\n", self.tableView);
//Problem line!!!!!!
[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
//The below lines also do nothing!!!!
//[self.tableView reloadData];
//[[self tableView] reloadData];
}
Anyone have any ideas??? I am at a total loss.
Cheers, Brett