두 개의 UITableView가 나란히 배치 된 응용 프로그램을 만들려고합니다. 왼쪽은 기사 카테고리를 나열하고 오른쪽은 기사 미리보기 (일종의 플립 보드 검색보기)를 표시합니다.side-by-side 데이터를 다시로드하는 중 UITableView
왼쪽 테이블 뷰의 didSelectRowAtIndexPath
에서 기사를 다운로드하고 올바른 UITableView에 미리보기를 표시해야합니다. 그러나, 나는이 일을 할 수없는 것 같습니다.
내 가정은 다운로드가 완료되기 전에 tableview에서 데이터를 다시로드한다는 것입니다. 어떤 제안? 편집을 할
:
여기에 내 현재 코드입니다 :
- (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