Это в 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