2012-02-06 5 views
1

두 개의 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 새로 고침하지 않습니다. 나는이 방법들이 문제가있는 곳이라고 생각한다.

+0

지금 어떻게하고 계시 며 어떤 문제를 겪고 계십니까? 해당되는 경우 가능한 한 상세하고 코드를 보여주십시오. – sosborn

답변

0

코드에 따라 UITableViewCell을 큐에서 제거한 경우 필요로하는 실제 셀을 수정하지 않고 이전 셀을 사용하게됩니다. 값을 다음과 같이 변경하십시오.

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
}//after this, use the tableView tag to identify. 

또한 미리보기 표 셀에 내용보기를 추가하고 있습니다. 이렇게 할 때 사용자 지정 UITableViewCell 클래스를 만드는 것이 좋습니다. 하위 뷰를 추가하는 것이 셀에서 작동하는 유일한 방법이라는 것을 알았으며 사용자 정의 클래스로 셀을 관리하는 것이 훨씬 쉽습니다.

나는 ArticlePreview에서 어떤 방법으로 다운로드를하고 있다고 가정합니다. 다운로드가 완료되면 tableView를 다시로드 할 필요가 없습니다. ArticlePreview 개체가 셀의 하위보기로 추가되었으므로 다운로드가 완료되면보기 콘텐츠 인 경우 setNeedsDisplay으로 전화하십시오.

+0

다운로드는 loadArticlePreview :'[downloadArticlesForIndex : [_ idx intValue]]'에서 수행됩니다. 그리고'setNeedsDisplay'를 어디에서 호출 할 지 모르겠습니다. 설명해 주시겠습니까? 감사합니다 – atnatn

+0

@atnatn : 오, 내 실수. 못 봤어. setNeedsDisplay를 잊어 버리십시오. articleInfos에 다운로드 한 데이터가 포함되어 있으면 괜찮습니다. 그것을 기록하여 그 권리가 있는지 확인하고 내가 제안한 것을 실행 해보십시오. 다시로드 할 때까지 다운로드가 완료된 경우에만 다시로드하기위한 코드가 적합합니다. 즉, downloadArticlesForIndex :는 다시로드 할 때까지 다운로드가 완료되었습니다. – MadhavanRP

+0

예, 그것에 대해 생각했지만 다운로드 할 때 테이블을 다시로드 할 때까지 이미 완료되었는지 확인하는 방법을 알 수 없습니다. – atnatn

0

백그라운드 스레드에서 테이블 뷰를 다시로드 할 수 없습니다. 그런 다음이 통해 UR 문제를 해결 -(void) loadArticlePreview: (NSNumber *)_idx 방법

희망 내부의 주 스레드에서이 메소드를 호출이
-(void)reloadTable { [self.articlePreviewTableView reloadData]; }

같은 방법을 만들어야합니다.

+0

불행히도 그렇지 않습니다. 고마워요 : D – atnatn

관련 문제