Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AbhishekApple

macrumors member
Original poster
Aug 5, 2010
86
0
TableView doesn't display values with asynchronous request
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
 
Have you told your table to reload the data anywhere?

Thanks it worked.

But i had to create another
@interface View3Controller : UIViewController {
NSMutableArray *arryProduct;
IBOutlet UITableView *tblvProd;
}

-(void)viewDidLoad{
[tblvProd reloadData];
}


Initially i had
@interface Product : UITableViewController {
NSMutableArray *tblProduct;
}
My question is , How to call a reload method with abv interface? "I have no instance of TableView".
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.