문제

데이터 소스의 결과를 표시하는 데 문제가 있습니다. 이 코드는 콘솔에서 다른 (그리고 올바른) 결과를 보여 주지만 시뮬레이터에서 모든 종류의 임의의 쓰레기가 나타납니다.

( "결과"는 클래스의 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];
}

이것이 배열의 메모리 보유 또는 배열의 문자열과 관련이있을 수 있다고 생각합니까? 나는 아직도 그 일이 없어도된다.

Marc Bessey에 대한 응답으로 편집 - 여기 모든 것이 기본 데이터 소스 방법이라고 생각합니다.

-(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;
}
도움이 되었습니까?

해결책

나는 당신이 게시 한 코드에 문제가 있다고 생각하지 않습니다. 코드에서 테이블보기의 데이터 소스를 구현하는 것이 더 가능성이 높습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top