TBXML を使用して http-XML ファイルを解析し、内容を UILabel & UIImageView に表示しています。XML への呼び出しは、非同期要求で行われます。
ログを表示すると、succesblock の最後のログ要素がすぐに出力されます。UILabel と UIImageview の変更は、数秒後にのみ表示されます。
XML の処理が終了した直後に IOS に UI を更新させるにはどうすればよいですか?
// Create a success block to be called when the async request completes
TBXMLSuccessBlock successBlock = ^(TBXML *tbxmlDocument) {
// If TBXML found a root node, process element and iterate all children
NSLog(@"PROCESSING ASYNC CALLBACK");
if (tbxmlDocument.rootXMLElement)
[self traverseElement:tbxmlDocument.rootXMLElement];
myArticle.Body = [[StringCleaner sharedInstance] cleanedString:myArticle.Body];
// myArticle.Body = [myArticle.Body stringByConvertingHTMLToPlainText];
self.articleBody.text = myArticle.Body;
self.articleBody.numberOfLines= 0;
self.articleBody.lineBreakMode = UILineBreakModeWordWrap;
[self.articleBody sizeToFit];
// set scroll view size
self.articleBodyScrollView.contentSize = CGSizeMake(self.articleBodyScrollView.contentSize.width, self.articleBody.frame.size.height);
NSURL *url = [NSURL URLWithString:myArticle.Photo];
NSData *data = [NSData dataWithContentsOfURL:url];
if (data != NULL)
{
UIImage *image = [UIImage imageWithData:data];
// articlePhoto = [[UIImageView alloc] initWithImage:image];
[self.articlePhoto setImage:image];
}else {
NSLog(@"no data");
}
NSLog(@"FINISHED PROCESSING ASYNC");
// [self printArticles];
};
// Create a failure block that gets called if something goes wrong
TBXMLFailureBlock failureBlock = ^(TBXML *tbxmlDocument, NSError * error) {
NSLog(@"Error! %@ %@", [error localizedDescription], [error userInfo]);
};
// tbxml = [[TBXML alloc] initWithURL:[NSURL URLWithString:someXML]];
tbxml = [[TBXML alloc] initWithURL:[NSURL URLWithString:records]
success:successBlock
failure:failureBlock];