1

I am doing JSON parsing, but my data is only shown in log and not in Tableview.

I am showing the main method of JSON parsing below. I would like to show the whole code but Stack Overflow doesn't allow me.

- (void)viewDidLoad 
{
    [super viewDidLoad];
    [_CenterTableview setHidden:NO];
    [_CenterTableview reloadData];

    NSString *str=@"http://www.vallesoft.com/vlcc_api/getservicenames.php?centrename=";
    NSURL * url=[NSURL URLWithString:str];
    NSURLRequest *req=[[NSURLRequest alloc]initWithURL:url];
    Connection1=[[NSURLConnection alloc]initWithRequest:req delegate:self];
    if (Connection1) {
        WebData1=[[NSMutableData alloc]init];
    }

    // [self.CenterTableview reloadData];
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSDictionary *json=[NSJSONSerialization JSONObjectWithData:WebData1 options:0 error:0];
    NSArray *city_info =[json objectForKey:@"city_info"];
    for(NSDictionary *dic in city_info)
    {
        NSArray *vlcc_service_name=[dic objectForKey:@"vlcc_service_name"];
        Centers=[[NSMutableArray alloc]initWithObjects:vlcc_service_name, nil];

        //This Nslog showing service name //
        NSLog(@"%@",vlcc_service_name);
    }
}

But in Tableview, it is not showing:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    cell.textLabel.text = [Centers objectAtIndex:indexPath.row];
    return cell;
}
2
  • Are you sure that You have set the tableview delegate to self? Commented Oct 8, 2015 at 11:35
  • Could any one help??i am trying till morning..Please solve this issue.. Commented Oct 8, 2015 at 11:47

1 Answer 1

1

You need to reload the tableview once you get the centers array filled in didFinishLoading

///Your code......
Centers=[[NSMutableArray alloc]initWithObjects:vlcc_service_name, nil];
[_CenterTableview reloadData];
////Your code.....
Sign up to request clarification or add additional context in comments.

4 Comments

Yes,This could help you. Try this out. You must have to reload the tableview whenever you update you data from web.
Actually main problem is that in enters no data shown thats why it is not showing in table view.. Could you please tell me how i show data in enters..?
@chandra Please suggest me how i accept this answer on stack overflow??
Moreover, don't init the the array every time you are fetching the contents from the web-service. Initialize it in viewDidLoad.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.