【发布时间】:2012-03-21 17:39:04
【问题描述】:
这是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
【问题讨论】:
-
你的问题真的不清楚...你能更好地解释你的问题是什么吗?
-
我的问题是我该怎么做才能重新加载tableView。就是这样。
-
不应该将
reloadData调用到self.aTableView,而不是[[self view] aTableView]?所以[self.aTableView reloadData] -
do reload消息打印出来了吗?如果是您没有正确引用表格视图。如果不是你有线程问题。 -
我描述了错误的命令。我已经正确运行 [self.aTableView reloadData] 或 [aTableView reloadData]。但这也不起作用。(“重新加载”消息也打印出来。)我尝试将 [NSLog] 写入 [cellForRowAtIndexPath:] 和 [tableView numberOfRowsInSection:]。 [tableView numberOfRowsInSection:] 已被调用。然而,[CellForRowAtIndexPath:] 似乎没有被调用。
标签: iphone objective-c uitableview uiviewcontroller reloaddata