Почему я не могу запустить reloadData? - PullRequest
0 голосов
/ 21 марта 2012

Это в UIViewController.Я хочу запустить reloadData для моего табличного представления, но оно не работает.

Сначала я вызываю fromGenre: из другого представления.Я начинаю NSURLConnection.Затем он вызывает connectionDidFinishLoading:.Тогда doParse:.После этого в этой функции я хочу вызвать reloadData.Но это не работает.

- (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

Ответы [ 2 ]

0 голосов
/ 17 сентября 2012

так что ... перезагрузка называется .. затем сделайте то, что предложил Эрик, и используйте отладчик :) ppl склонны использовать его недостаточно: P устанавливает точку останова прямо перед перезагрузкой и смотрит на переменные:

poGenreTrack

po aTableView

po aTableView.dataSource

0 голосов
/ 22 марта 2012

Вы должны попробовать использовать отладчик. [[self view] aTableView] кажется странным способом ссылки на ваше табличное представление. Если это свойство контроллера, вы должны использовать self.aTableView, а если это обычная переменная экземпляра, вы должны просто использовать aTableView.

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