i can parse data and see the output also but i am not able to display them in table view
problem is 1st my tableviews code are executing then rest functions are working that’s why i am getting 0 , how to avoid this ??
this is my code
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@" value %d",[jsonArray count]);// always 0
return [jsonArray count];
}
in this method also i am getting 0 valuee
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath { NSDictionary *aTweet = [jsonArray objectAtIndex:[indexPath
row]]; NSLog(@ " divy is
%@",aTweet);// nothing
}
other codes
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
NSError *error;
SBJSON *json = [[SBJSON new] autorelease];
NSDictionary *data = (NSDictionary *) [json objectWithString:responseString error:nil];
NSDictionary *menu = (NSDictionary *) [data objectForKey:@"name"];
//label.text=[dict objectForKey:@"firstName"];
// parsing all the items in to the NSArray
NSArray *items = (NSArray *) [menu objectForKey:@"phoneNumber"];
int ndx;
//NSDictionary *stream;
for (ndx = 0; ndx< items.count; ndx++) {
stream = (NSDictionary *)[items objectAtIndex:ndx];
NSLog(@"This is the title of a stream: %@", [stream valueForKey:@"type"]);
[jsonArray addObject:stream];
}
NSLog(@" aray is %@",jsonArray);// show all data working
NSLog(@" sterab is %@",[stream valueForKey:@"home"]);// this is also working
and this is my view did load()
- (void)viewDidLoad {
jsonArray= [[NSMutableArray alloc] init] ;
[super viewDidLoad];
responseData = [[NSMutableData data] retain];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://Json/Number.json"]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
label.text = [NSString stringWithFormat:@"Connection failed: %@", [error description]];
}
Possibly, the problem is that you data doesn’t load immediately. And
UITableView, when created, stores necessary data in some sort of cache. This allows to avoid often calls of data source’s methods, liketableView:numberOfRowsInSection:and others. So you should explicitly callUITableView‘sreloadDatamethod to refresh table.To solve the problem, you should do something like this:
viewDidLoadjust show some spinner to indicate program activity.connectionDidFinishLoading:after all data was initialized, call[yourTableView reloadData].