我試圖創建一個應用程序並排放置兩個UITableViews。左側列出文章類別,右側列出文章預覽(類似flipboard的搜索視圖)。並排重新加載數據UITableView
在左側桌面的didSelectRowAtIndexPath
上,我應該下載文章並在右側的UITableView上顯示預覽。但是,我似乎無法完成這項工作。
我的假設是我在下載完成之前重新加載tableview上的數據。有什麼建議麼?
EDITED:
這裏是我當前的代碼:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
if (tableView.tag == 1)
{
//if it's the left tableView (no problem here)
NSDictionary *catDic = [[Category categories] objectAtIndex:indexPath.row];
cell.textLabel.text = [catDic valueForKey:@"name"];
cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:[UIFont labelFontSize]];
}
if (tableView.tag == 2)
{
//if it's the right tableView
ArticlePreview *articleView = [[ArticlePreview alloc] initFlexibleHeightRowForArticleInfo:[self.articleInfos objectAtIndex:indexPath.row]];
//ArticlePreview is a custom class that create the articlePreview view,
//articleInfos is a variable that holds the articles in core data
[cell.contentView addSubview:articleView];
[articleView release];
}
}
return cell;
}
-(void) loadArticlePreview: (NSNumber *)_idx
{
[Category downloadArticlesforIndex:[_idx intValue]];
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [delegate managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"ArticleInfo" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSError *error;
self.articleInfos = [context executeFetchRequest:fetchRequest error:&error];
[fetchRequest release];
[self.articlePreviewTableView reloadData];
//articlePreviewTableView is the right table view identifier, hooked with IBOutlet and all
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView.tag == 1) //if it's the left table
{
[self performSelectorInBackground:@selector(loadArticlePreview:) withObject:[NSNumber numberWithInt:indexPath.row]];
}
}
的問題是正確的tableview不刷新。我認爲這些方法可能是問題所在。
你現在怎麼做,你跑什麼毛病?請儘可能具體,並在適用的情況下顯示代碼。 – sosborn 2012-02-06 02:59:02