2009-03-31 5 views
0

데이터 소스의 결과를 표시하는 데 문제가 있습니다. 이 코드는 콘솔에 다른 결과를 표시하지만 시뮬레이터에서 모든 종류의 임의의 결과를 가져옵니다.코코아 터치 테이블 데이터 소스 문제

("결과"클래스에 대한 NSMutableArray의 호텔입니다.) 나는이 메모리 배열의 유지, 또는 배열의 문자열을 함께 할 수있는 뭔가가있을 같은데요

-(void) handleSearchForKeywords: (NSString *) keywords { 
    [results removeAllObjects]; 
    int r = rand() % 10; 
    for(int i = 0; i < r; i++) { 
     [results addObject:[NSString stringWithFormat:@"test %i: %@", i, keywords]]; 
    } 
    [self reloadTheTable]; 
} 

-(void) reloadTheTable { 
    NSLog(@"current array contents: %@", results); 
    [tableView reloadData]; 
}

? 나는 아직도 그 걸림돌이 없다고 생각합니다.

-

-(NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) section { 
    return [results count]; 
} 

-(UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath { 
    static NSString *SearchViewControllerCell = @"SearchViewControllerCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SearchViewControllerCell]; 
    if(cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame: CGRectZero reuseIdentifier: SearchViewControllerCell] autorelease]; 
     NSUInteger row = [indexPath row]; 
     [cell setText:[results objectAtIndex:row]]; 
    } 
    return cell; 
}

답변

1

나는 문제가 당신이 게시 한 코드에서 생각하지 않습니다 [마크 Bessey에 따라 편집 내가 여기있는 모든 생각은 기본 데이터 소스 방법입니다]. 테이블 뷰의 데이터 소스를 구현하는 코드에서 더욱 그렇습니다.

+0

당신이 옳았습니다. 셀의 텍스트를 설정하는 비트는 캐싱 루프 안에있었습니다. if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame : CGRectZero reuseIdentifier : blah] autorelease]; [셀 setText : [결과 objectAtIndex : 행]]; } ^ 잘못되었습니다. –