-5

This is in UIViewController. I want to run reloadData on my table view, but it does not work.

First, I call fromGenre: from another view. I start an NSURLConnection. Then it calls connectionDidFinishLoading:. Then doParse:. After that, in this function, I want to call reloadData. But it does not run.

- (void)viewDidLoad{
[super viewDidLoad];    
}

//Parse function
-(void)doParse{   
    NSString *jsonString = [[NSString alloc]initWithData:result encoding:NSUTF8StringEncoding];
    data2=[[[[jsonString JSONValue]] objectForKey:@"feed"] objectForKey:@"entry"];
     trackGenre = [[NSMutableArray alloc]init];
    for (NSDictionary *dic in data2) {
        NSString *artistName = [[dic objectForKey:@"im:artist"]objectForKey:@"label"];
         NSMutableDictionary *dicData = [NSMutableDictionary dictionary];
        [dicData setValue:artistName forKey:@"artist"];
        [trackGenre addObject:dicData];
    }
    **//[self.aTableView reloadData];
    /*
     [ self.aTableView performSelectorOnMainThread:@selector( reloadTableView )
                                       withObject:nil
                                    waitUntilDone:YES
     ];*/
    [self performSelectorOnMainThread:@selector(reloadTableView) withObject:nil waitUntilDone:YES];
    //[self reloadTableView];**
}

-(void)reloadTableView{
[[[self view] aTableView] reloadData];
NSLog(@"do reload");
}


- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
//[self doParse];
[self performSelectorOnMainThread:@selector(doParse) withObject:nil waitUntilDone:YES];    
}


-(void)fromGenre:(NSURLRequest *)urlRequest{
NSLog(@"urlRequest:%@",urlRequest);
aConnection = [NSURLConnection connectionWithRequest:urlRequest delegate:self];
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return trackGenre ? [trackGenre count]:100;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"second_VC_Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    cell.textLabel.text = [[trackGenre objectAtIndex:indexPath.row]objectForKey:@"track"];        
return cell;
}

@end
Tetsurou Uno
  • 1
  • 1
  • 2
  • 2
    Your question is really unclear...Can you explain better what your problem is? – Manlio Mar 21 '12 at 19:28
  • My problem is that I'm what to do in order to reloadData the tableView. That's all. – Tetsurou Uno Mar 22 '12 at 00:02
  • Shouldn't the `reloadData` call be to `self.aTableView`, not `[[self view] aTableView]`? So `[self.aTableView reloadData]` –  Mar 22 '12 at 00:21
  • Is the `do reload` message printing out? If it is you're not referencing the table view properly. If it's not you have a threading issue. –  Mar 22 '12 at 00:28
  • I described the wrong command.I've run correctly [self.aTableView reloadData], or [aTableView reloadData]. But that does not work either.("do reload" message printed out either.) I tried writing [NSLog] to [cellForRowAtIndexPath:] and [tableView numberOfRowsInSection:]. [tableView numberOfRowsInSection:] had been called. [CellForRowAtIndexPath:] does not seem to be called, however. – Tetsurou Uno Mar 22 '12 at 03:30

2 Answers2

0

so.. reload is called.. then do what erik suggested and use the debugger :) ppl tend to not use it enough :P set a breakpoint right before reload and look at the variables:

po GenreTrack

po aTableView

po aTableView.dataSource

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
0

You should try using the debugger. [[self view] aTableView] seems like a weird way to reference your table view. If it's a property of the controller you should use self.aTableView and if it's a regular instance variable, you should just use aTableView.

-(void)reloadTableView{
    [aTableView reloadData];
    NSLog(@"do reload");
}
Erik B
  • 40,889
  • 25
  • 119
  • 135
  • I described the wrong command. I've wrote correctly [self.aTableView reloadData], or [aTableView reloadData] already. But that does not work either. – Tetsurou Uno Mar 22 '12 at 05:23