UITableView
에 표시 할 SQLite 데이터베이스의 일부 데이터를로드하고 있습니다. 사용자가 차단되지 않고 테이블이 빨리 표시되는지 확인하기 위해 대기열을 만들고 데이터베이스 작업을 추가하여 백그라운드에서 실행합니다.NSOperationQueue 및 UITableView
추가 기능은 정상적으로 작동하지만 정상적으로 작동하지만 일부 이유로 인해 일부 행이 데이터로 업데이트되지 않습니다!
행을 클릭하면 행이 내 데이터로 업데이트되지만 UI를 업데이트하는 방법을 찾지 못하는 것처럼 데이터가 올바르게 설정되어 있다는 것을 알고 있습니다! setNeedDisplay
등을 사용하여 모든 것을 시도했지만 아무런 효과가 없습니다!
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell* cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.textAlignment = UITextAlignmentRight;
cell.textLabel.numberOfLines = 0;
cell.textLabel.font = [UIFont systemFontOfSize:14];
}
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.text = @"Loading ...";
cell.tag = indexPath.row;
NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(setCellData:)
object:cell];
[queue addOperation:op];
[op release];
return cell;
}
- (void) setCellData:(UITableViewCell *)cell{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
sqlite3_stmt *statement2;
NSString *sqlStr = [NSString stringWithFormat:@"SELECT * FROM poemdata WHERE catid='%d' GROUP BY poemid LIMIT 1 OFFSET %d",catId,cell.tag];
// NSLog(@"%@",sqlStr);
sqlite3_prepare_v2(database, [sqlStr cStringUsingEncoding:NSASCIIStringEncoding], -1, &statement2, nil);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if(sqlite3_step(statement2) == SQLITE_ROW){
cell.textLabel.text = [[NSString alloc] initWithUTF8String: (char *)sqlite3_column_text(statement2, 3)];
cell.tag = sqlite3_column_int(statement2, 6);
}else{
cell.textLabel.text = @"Error";
}
sqlite3_finalize(statement2);
[pool release];
}
문제는 크기입니다.이 데이터베이스는 너무 커서 모든 행을로드 할 수 없으며 일부를로드하는 로직은 복잡하지 않습니다. 그래서 나는 내가 한 일을 할 필요가 있습니다. 문제는 화면에서 셀을 업데이트하기 위해해야 할 일입니다. 대답의 그림 부분에 [cell setNeedDisplay]를 추가하면 도움이되지 않습니다. 여기서 문제는 타이밍입니다. 데이터가 설정되기 전에 셀이 표시되고 어떤 이유로 든 새로 고쳐지지 않습니다. – Amir
@Amir 문제가 크기가 아닌 경우 (흔하지 않은 문제는 아닙니다) 동일한 유형의 페이징 동작을 구현하려는 경우 로컬 데이터베이스 또는 네트워크 연결에서 발생하든 비슷한 문제가있는 많은 응용 프로그램에서 발생합니다. 큰 초기 세트 (셀 레이아웃의 복잡성에 따라 100-200 레코드)를로드해야하고 사용자가 목록 하단에 도달하면 다른 25-50을로드하고 처음 25-50을 롤링 윈도우로 유지해야합니다 메모리에. 게시 된 코드를 작동시키는 것만 큼 복잡한 것은 아닙니다. – theChrisKent
크리스, 고맙습니다. 내 논리를 변경하는 방법을 고려해 보겠습니다. :) 저는 아직도 이것이 작동하지 않는 이유를 알고 싶습니다. – Amir