TableView doesn't display values with asynchronous request
It works with Synchronus request i.e Tableview gets filled by value
Please help
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://xyz.com/abc.jsp"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
//suppose returned string is a,b,v,d,e
NSArray *arry = nil;
arry = [responseString componentsSeparatedByString:@","];
tblProduct =[[NSMutableArray alloc] initWithArray:arry];
[responseString release];
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
NSString *cellValue = [tblProduct objectAtIndex:indexPath.row];
cell.text = cellValue;
return cell;
}
It works with Synchronus request i.e Tableview gets filled by value
Code:
- (void)viewDidLoad
{
NSURL *url = [NSURL URLWithString:@"http://xyz.com/abc"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[B][request startSynchronous];[/B]
// [request startAsynchronous] doesn't work
NSError *error = [request error];
if (!error) {
NSString *response = [request responseString];
NSArray *arry = nil;
arry = [responseString componentsSeparatedByString:@","];
tblProduct =[[NSMutableArray alloc] initWithArray:arry];
}
}
Please help