당신의 추측이 맞습니다. 사용자 인터페이스에 대한 업데이트는 프로그램 제어가 주 실행 루프로 돌아갈 때만 수행됩니다. NSXMLParser
그러나 완전히 동 기적으로 작동합니다. parse
메서드는 (위임 함수 등을 호출하는) 전체 XML 데이터를 구문 분석하고 구문 분석이 완료 될 때만 반환합니다. 따라서 reloadData
을 parser:didEndElement:...
에 호출하면 즉각적인 효과가 나타나지 않습니다.
XML 데이터를 파싱하는 것은 정말 그냥 parse
메소드가 반환 될 때, 당신은 별도의 스레드로 파싱 작업을 이동해야 reloadData
를 호출 할 수 없습니다 너무 많은 시간이 걸리는 경우 즉시
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[myParser parse];
});
dispatch_async
반환 및 파싱은 백그라운드 스레드에서 수행됩니다. 따라서 대리자 메서드는 백그라운드 스레드에서 호출되기도합니다. UI를 업데이트는 메인 스레드에서 수행해야하기 때문에 parser:didEndElement:...
에서 다음과 같이 진행할 수 :
YourType newObject = ... // create new object from XML data
dispatch_async(dispatch_get_main_queue(), ^{
// assuming that self.dataArray is your data source array for the table view
int newRow = [self.dataArray count]; // row number for new object
[self.dataArray addObject:newObject]; // add to your data source
// insert row in table view:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:newRow inSection:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];
});
애니메이션과 함께 "부드러운"UI 업데이트를 제공해야 insertRowsAtIndexPaths
대신 reloadData
의 사용.
샘플 코드에 구문 오류가 너무 많아서 도움이되지 않기를 바랍니다. 그렇지 않으면 물어보십시오.
감사합니다 * 너무 * 많이, 마틴 R! 나는 이것을 분명히 시도 할 것이다. –