Я пытаюсь создать приложение, в котором есть два UITableView, размещенных бок о бок. В левом списке перечислены категории статей, а в правой отображается предварительный просмотр статьи (например, вид поиска флиппарта).Перезагрузка данных по бок о бок UITableView
На левой табличке didSelectRowAtIndexPath
, я должен загрузить статью и отобразить превью справа UITableView. Однако я не могу сделать эту работу.
Мое предположение заключается в том, что я загружаю данные в виде таблицы перед завершением загрузки. Какие-либо предложения?
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