2011-11-11 3 views
0

내보기 컨트롤러 중 하나에서 UITableView가 있는데, 내 앱의 여러 부분에서 로그 메시지로 비동기 적으로 업데이트됩니다. 그것은 잘 작동했지만 오늘은 이상한 버그를 발견했습니다. 약 2 시간이 지나면 전체 테이블 뷰가 공백으로 바뀝니다. 셀, 라인 구분 기호, 배경색이 없습니다.iPhone4 iOS5는 배경 선택기에서 UITableView를 새로 고치는 것이 안전합니까?

이 테이블 뷰에는 2 개의 항목 경로 만 있습니다.

있는 tableview 그것의 모든 데이터를 "잃을"내가이있는 NSMutableArray이 부족한 용량 할당 된 것으로 의심

-(void)setContextActionWithTitle:(NSString *)title description:(NSString *)description 

한 가지에 응답을 중지하는 원인이 될 수 무엇

NSMutableArray* tableViewCellData; 

//in the init method: 
tableViewCellData = [[NSMutableArray alloc]initWithCapacity:15]; 

-(void)setContextActionWithTitle:(NSString *)title description:(NSString *)description 

     ContextConsoleLogItem* temp = [[ContextConsoleLogItem alloc] initWithDate:[NSDate date] title:title message:description contextAction:kNoContextAction]; 
     [tableViewCellData insertObject:temp atIndex:0]; 
     [contextActionTableView reloadData]; 
    } 

//pretty standard data source management 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 

    // Return the number of sections. 
    return kNumberOfSections; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return [tableViewCellData count]; 
} 

//here's how the cell displays itself. 
    #pragma mark - 
    #pragma mark Cell customization 
    -(void)configureCell:(UITableViewCell*) cell atIndexPath:(NSIndexPath*) indexPath 
    { 
     ContextConsoleLogItem* logItem = [tableViewCellData objectAtIndex:indexPath.row]; 

     cell.backgroundColor = [UIColor blackColor]; 
     cell.textLabel.textColor = [UIColor whiteColor]; 
     cell.textLabel.font = [UIFont systemFontOfSize:9]; 
     cell.detailTextLabel.textColor = [UIColor whiteColor]; 
     cell.textLabel.text = logItem.message; 
     cell.textLabel.numberOfLines =3; 
    } 

. 그것은 최대한 빨리 최대 용량에 도달합니다. 위의 방법을 사용하여 게시 된 메시지 중 일부는 performSelectorInBackground에 대한 호출에서 온 것입니다. 내 배경 선택기 중 하나가 NSMutableArray의 용량에 도달하여 다시 할당하지 못할 수 있습니까? 하지만 다시 빈 테이블 뷰에도 셀이 있어야하므로 줄 구분 기호를 볼 수 있어야합니다.

setContextActionWithTitle:description:performSelectorOnMainThread으로 바꿔야합니까?

테이블 뷰를 업데이트하기 위해 2 번의 별도의 호출이 이루어지고 어떻게 든 테이블이 일관성없는 상태로 남았습니까? (여기에 예외가 없습니다)

이것은 아주 수수께끼가없는 행동이며, 디버깅에 도움이됩니다.

답변

6

UIKit의 아무 것도 건드리지 마십시오. 이제까지. 내가 의심

+0

하하, 명확하게 요점을 말하자면 코드를 다시 작성하겠습니다. –

+0

백그라운드 스레드에서 UIKit 객체에 할 수있는 일은 매우 제한되어 있습니다. 그것은 잘 문서화되어있다. 명시 적으로 지원되는 것으로 문서화되지 않은 경우에는 수행하지 마십시오. – bbum

+0

예, 예, 알고 있습니다. 좋은 사운드 비트를 만들지 않습니다. –

1

한 가지가있는 NSMutableArray는 확실히 용량이 부족

없는 경우에 할당 된 것입니다. As stated in the docs :

가변 배열은 필요에 따라 확장됩니다. numItems는 객체의 초기 용량을 간단히 설정합니다.

짐이 맞습니다. 배경 스레드에서 UIKit을 절대 터치하지 마십시오.

관련 문제