当uiwebview loadhtmlstring方法给字符串的内容很重时崩溃应用程序

时间:2011-11-29 18:48:29

标签: iphone objective-c ios

我正在做一个显示评论和许多子评论的应用程序。我在htmlstring中维护所有这些信息并将其提供给UIWebview -(void)loadhtmlstring:(NSString *)str baseUrl:(NSUrl *)url;当评论很少时,这样可以正常工作。如果注释增加了显示内存警告的应用程序崩溃。

以下是代码:

NSMutableString *htmlString = [[NSMutableString alloc]
                               initWithString:@"<html><body>"];

for(int i=0;i < commentsCount;++i){
    Comment *comment= [self.commetsArray objectatindex:i];
    [htmlString appendFormat:"<h2>%@</h2>",comment.title];
    [htmlString appendFormat:"<h3>%@</h3>",comment.description];
    for (int j=0;j<comment.subCommentCount;++j){
        SubComment *subComment= [comment.subCommetsArray objectatindex:j];
        [htmlString appendFormat:"<h2>%@</h2>",subComment.title];
        [htmlString appendFormat:"<h3>%@</h3>",subComment.description];
    }
}

[htmlString appendString:@"</body></html>"];
[self.commentWebview
 loadHTMLString:htmlString
        baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
[htmlString release];

当commentscount为20-40时,应用程序正常工作,当commentscount大于40时,应用程序崩溃。是否存在NSMutableString或UIWebview错误?

0 个答案:

没有答案