0

我有一个问题希望你能帮助我。

NSMutatableAttributedString用来加载html,UILabel但应用程序一直崩溃

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{

    self.attrStr = [[NSMutableAttributedString alloc] initWithData:[desc dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
});

我试图添加dispatch_async,但没有任何改变。

所以请帮助我,

4

1 回答 1

0

您不能在块中分配属性。它可以在块中分配,但是当块离开堆或堆栈时,指针也会如此。

除非您在属性进入块之前执行 __block

我知道如果我想访问块内的布尔值并在退出时保留该值,我会做类似的事情

__block BOOL myBool = NO;

然后在我的块中我可以设置它 ^{ myBool = YES; }

//myBool is YES now!

给这一次

[链接] https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Blocks/Articles/bxVariables.html

于 2014-11-22T07:59:59.447 回答