2015-01-07 3 views
2

NSAttributedString에 HTML 텍스트를 할당합니다. 이 속성 문자열은 UitableViewCell in cellForRowAtIndexPath Method에있는 UILabel 중 하나에 지정됩니다.
셀 재사용으로 인해 initWithData: method is causing sluggishness at UI.
따라서 글로벌 큐에서 실행할 코드를 만들었습니다. 나는 이런 식으로 뭔가를하고 있어요 :NSAttributedString에 HTML 텍스트를 할당하면 EXC_BAD_ACESS가 글로벌 큐에 throw됩니다.

-(void)assignAttrText:(NSDictionary *)dict{ 

NSDictionary *msgThreadDict = [dict objectForKey:@"messgDict"]; 
__block DRMessageThreadTableViewCell *cell = [dict objectForKey:@"cell"]; 
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ 
    NSError *err = nil; 
    NSAttributedString *attributedString = 
    [[NSAttributedString alloc] 
    initWithData: [[msgThreadDict objectForKey:@"text"] dataUsingEncoding:NSUTF8StringEncoding] 
    options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } 
    documentAttributes: nil 
    error: &err]; 
    if(err){ 
     NSLog(@"Unable to parse label text: %@", err); 
    } 
    else{ 
     cell.messageTextLabel.attributedText = attributedString; 

    } 
}); 

단서를 응용 프로그램을 일으키는 것과 같은 방법에 EXC_BAD_ACCESS와 충돌 : 다음,

[[NSAttributedString alloc] 
    initWithData: [[msgThreadDict objectForKey:@"text"] dataUsingEncoding:NSUTF8StringEncoding] 
    options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } 
    documentAttributes: nil 
    error: &err]; 

답변

0

[msgThreadDict objectForKey:@"text"]에서 NSData *mydata 개체를 확인 [[NSAttributedString alloc] initWithData: mydata ...를 사용

나는 당신의 객체가 NSData 유형이 아니고, 문자열을 사용하여 데이터로 변환 했으므로, EXC_BAD_ACCESS이라고 생각합니다.

NSString *ceva = [NSString stringWithFormat:@"%@",[msgThreadDict objectForKey:@"text"]]; 
NSData *mydata = [ceva dataUsingEncoding:NSUTF8StringEncoding]; 
+1

글로벌 대기열에서 코드를 실행하면 충돌이 해결되지 않습니다. 그러나 performSelectorOnMainThread를 수행 할 때 전역 대기열을 제거하면 잘 작동하지만 여전히 셀 재사용이 느려지 게됩니다. –