- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作一个新闻阅读应用。我有一个用作分页 Controller 的 ArticleDetailPagingVC。这有一个带有多个 ArticleDetailViewController 的 UIScrollView。
ArticleDetailViewController 内是一个处理文章文本的 UIWebView。
更改一些代码后,我在尝试向 UIWebView 中注入(inject) HTML 字符串时收到 EXC_BAD_ACCESS。我最终找到了 NSZombie's,我发现了它:
如屏幕截图所示,NSZombie 指向设置 ArticleDetailViewController 的框架,我认为这是不正确的。
如果我注释掉将 HTMLString 注入(inject)我的 UIWebView 的代码行, View 将按应有的方式显示,UIWebView 中没有任何数据。
WebView 创建为 IBOutlet:
@property (nonatomic) IBOutlet UIWebView *webView;
委托(delegate)设置为自身(ArticleDetailViewController)
此外,它会在调用任何 UIWebView 委托(delegate)方法之前崩溃。
我确定问题不是:
我不知道过早发布了什么会导致崩溃所以我的问题是,如何调试这样的 NSZombie?或任何其他指针非常感谢。
PagingVC.h
#import <UIKit/UIKit.h>
#import "DDScrollViewController.h"
#import "ThumbArticle.h"
#import "NewsArticle.h"
#import "MBProgressHUD.h"
#import "DDScrollViewDelegate.h"
@interface ArticleDetailPagingVC : UIViewController <UIScrollViewDelegate,MBProgressHUDDelegate>
//View
@property (nonatomic) IBOutlet UIScrollView *scrollView;
//Data
@property (nonatomic) ThumbArticle *selectedThumbArticle;
@property (nonatomic) NewsArticle *selectedNewsArticle;
@property (nonatomic) int indexOfSelectedArticle;
@property (nonatomic) NSMutableArray *dataList;
@property (nonatomic) NSInteger selectedPage;
@property (nonatomic) BOOL dataSet;
@property (nonatomic) MBProgressHUD *mbProcess;
-(id)initWithDataList:(NSMutableArray*)dataList;
@end
PagingVC.m
#import "ArticleDetailPagingVC.h"
#import "ArticleDetailViewController.h"
@interface ArticleDetailPagingVC ()
-(void)setupView;
-(void)setupViewWithThumbArticles;
-(void)setupViewWithNewsArticles;
@end
@implementation ArticleDetailPagingVC
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.dataSet = NO;
}
return self;
}
-(id)initWithDataList:(NSMutableArray*)dataList
{
self = [super init];
if (self) {
self.dataSet = NO;
self.dataList = [NSMutableArray arrayWithArray:dataList];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (self.selectedThumbArticle) {
self.indexOfSelectedArticle = [self.dataList indexOfObject:self.selectedThumbArticle];
} else if (self.selectedNewsArticle) {
self.indexOfSelectedArticle = [self.dataList indexOfObject:self.selectedNewsArticle];
}
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self setupView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark -
#pragma mark Custom Methods
-(void)setupView
{
if (self.dataList.count > 0) {
id object = [self.dataList objectAtIndex:0];
if ([object isKindOfClass:[NewsArticle class]]) {
} else if ([object isKindOfClass:[ThumbArticle class]]) {
ArticleDetailViewController *articleDetailVC = [[ArticleDetailViewController alloc] init];
articleDetailVC.selectedThumbArticle = [self.dataList objectAtIndex:self.indexOfSelectedArticle];
articleDetailVC.view.frame = CGRectMake(self.indexOfSelectedArticle * self.scrollView.frame.size.width, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height);
[self.scrollView addSubview:articleDetailVC.view];
//[articleDetailVC layoutViewWithThumbArticle:[self.dataList objectAtIndex:self.indexOfSelectedArticle]];
}
self.scrollView.contentSize = CGSizeMake(self.dataList.count * self.scrollView.frame.size.width, self.scrollView.frame.size.height);
[self.scrollView setContentOffset:CGPointMake(self.indexOfSelectedArticle * self.scrollView.frame.size.width, 0) animated:NO];
self.dataSet = YES;
}
}
-(void)setupViewWithThumbArticles
{
//Set the selected article first
/*
ArticleDetailViewController *articleDetailVC = [[ArticleDetailViewController alloc] init];
dispatch_async(dispatch_get_main_queue(), ^{
articleDetailVC.view.frame = CGRectMake(indexOfSelectedArticle * self.scrollView.frame.size.width, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height);
[self.scrollView addSubview:articleDetailVC.view];
});
[self.viewControllers replaceObjectAtIndex:indexOfSelectedArticle withObject:articleDetailVC];
[articleDetailVC layoutViewWithThumbArticle:[self.dataList objectAtIndex:indexOfSelectedArticle]];
//Then loop through the rest to add them to the scrollview
*/
int i = 0;
for (ThumbArticle *article in self.dataList) {
if (i != self.indexOfSelectedArticle) {
ArticleDetailViewController *articleDetailVC = [[ArticleDetailViewController alloc] init];
dispatch_async(dispatch_get_main_queue(), ^{
articleDetailVC.view.frame = CGRectMake(i * self.scrollView.frame.size.width, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height);
[self.scrollView addSubview:articleDetailVC.view];
});
//[self.viewControllers replaceObjectAtIndex:i withObject:articleDetailVC];
}
i++;
}
dispatch_async(dispatch_get_main_queue(), ^{
self.scrollView.contentSize = CGSizeMake(i * self.scrollView.frame.size.width, self.scrollView.frame.size.height);
[self.scrollView setContentOffset:CGPointMake(self.indexOfSelectedArticle * self.scrollView.frame.size.width, 0) animated:NO];
});
}
-(void)setupViewWithNewsArticles
{
int indexOfSelectedArticle = [self.dataList indexOfObject:self.selectedNewsArticle];
ArticleDetailViewController *articleDetailVC = [[ArticleDetailViewController alloc] init];
dispatch_async(dispatch_get_main_queue(), ^{
articleDetailVC.view.frame = CGRectMake(indexOfSelectedArticle * self.scrollView.frame.size.width, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height);
[self.scrollView addSubview:articleDetailVC.view];
});
//[self.viewControllers replaceObjectAtIndex:indexOfSelectedArticle withObject:articleDetailVC];
[articleDetailVC layoutViewWithNewsArticle:[self.dataList objectAtIndex:indexOfSelectedArticle]];
int i = 0;
for (NewsArticle *article in self.dataList) {
if (i != indexOfSelectedArticle) {
ArticleDetailViewController *articleDetailVC = [[ArticleDetailViewController alloc] init];
dispatch_async(dispatch_get_main_queue(), ^{
articleDetailVC.view.frame = CGRectMake(i * self.scrollView.frame.size.width, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height);
[self.scrollView addSubview:articleDetailVC.view];
});
//[self.viewControllers replaceObjectAtIndex:i withObject:articleDetailVC];
}
i++;
}
self.scrollView.contentSize = CGSizeMake(i * self.scrollView.frame.size.width, self.scrollView.frame.size.height);
[self.scrollView setContentOffset:CGPointMake(indexOfSelectedArticle * self.scrollView.frame.size.width, 0) animated:NO];
}
#pragma mark -
#pragma mark UIScrollView Delegate Methods
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (fmodf(scrollView.contentOffset.x, scrollView.frame.size.width) == 0) {
if (self.dataSet) {
self.selectedPage = scrollView.contentOffset.x / self.scrollView.frame.size.width;
ArticleDetailViewController *articleDetailVC = [[ArticleDetailViewController alloc] initWithNibName:@"ArticleDetailViewController" bundle:nil];
articleDetailVC.view.frame = CGRectMake(self.selectedPage * self.scrollView.frame.size.width, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height);
[self.scrollView addSubview:articleDetailVC.view];
[articleDetailVC layoutViewWithThumbArticle:[self.dataList objectAtIndex:self.selectedPage]];
}
}
}
#pragma mark -
#pragma mark MBProgressHUDDelegate methods
- (void)hudWasHidden
{
[self.mbProcess removeFromSuperview];
}
@end
ArticleDetailViewController.h
#import "DDViewController.h"
#import "ThumbArticle.h"
#import "NewsArticle.h"
#import "MBProgressHUD.h"
#import "DDAsyncParser+NewsArticles.h"
@interface ArticleDetailViewController : DDViewController <MBProgressHUDDelegate,UIWebViewDelegate,ParserDelegate>
//View
@property (nonatomic,strong) IBOutlet UIView *contentView;
@property (nonatomic) IBOutlet UIImageView *image;
@property (nonatomic) IBOutlet UILabel *labelCategory;
@property (nonatomic) IBOutlet UILabel *labelImgCaption;
@property (nonatomic) IBOutlet UILabel *labelEdition;
@property (nonatomic) IBOutlet UIWebView *webView;
@property (nonatomic) IBOutlet UIActivityIndicatorView *activity;
@property (nonatomic) NSUInteger textFontSize;
@property (nonatomic) MBProgressHUD *mbProcess;
//Data
@property (nonatomic) ThumbArticle *selectedThumbArticle;
ArticleDetailViewController.m
#import "ArticleDetailViewController.h"
#import "DDUtilities.h"
#import "DDUserDefaults.h"
#import "NewsArticle.h"
#import "DDFeedParser.h"
@interface ArticleDetailViewController ()
@property (nonatomic) NewsArticle *parsedNewsArticle;
-(void)loadData;
-(void)updateImageCaptionLabel;
-(void)populateWebView;
@end
@implementation ArticleDetailViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
[self.view addSubview:self.contentView];
((UIScrollView*)self.view).contentSize = self.contentView.frame.size;
self.dataSet = NO;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (!self.dataSet) {
[[DDAsyncParser sharedInstance] parseArticleWithXMLURL:self.selectedThumbArticle.articleXMLUrl delegate:self];
}
}
- (void)viewWillUnload
{
[self.webView setDelegate:nil];
[self.webView stopLoading];
}
- (void)viewWillDisappear:(BOOL)animated{
[self.webView setDelegate:nil];
[self.webView stopLoading];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark -
#pragma mark Public Methods
-(void)layoutViewWithThumbArticle:(ThumbArticle*)article
{
if (!self.dataSet) {
self.selectedThumbArticle = article;
[[DDAsyncParser sharedInstance] parseArticleWithXMLURL:self.selectedThumbArticle.articleXMLUrl delegate:self];
}
}
-(void)layoutViewWithNewsArticle:(NewsArticle*)article
{
if (!self.dataSet) {
self.parsedNewsArticle = article;
[self loadData];
}
}
#pragma mark -
#pragma mark Private Methods
-(void)loadData
{
self.labelCategory.text = self.parsedNewsArticle.articleCategory;
self.labelCategory.font = kCalibriBold14;
self.labelCategory.textColor = kGrayColor;
self.labelEdition.text = self.parsedNewsArticle.articleEdition;
self.labelEdition.font = kCalibriBold14;
self.labelEdition.textColor = kGrayColor;
[self updateImageCaptionLabel];
[self populateWebView];
self.dataSet = YES;
}
-(void)updateImageCaptionLabel
{
self.labelImgCaption.text = @"";
NSString *imgAuthor = @"";
if (self.parsedNewsArticle.articleImgAuthor.length != 0) {
imgAuthor = [NSString stringWithFormat:@"Foto: %@",self.parsedNewsArticle.articleImgAuthor];
}
NSString *imgCaption = @"";
if (self.parsedNewsArticle.articleImgDescription.length != 0) {
imgCaption = [NSString stringWithFormat:@"%@ \n%@",self.parsedNewsArticle.articleImgDescription,imgAuthor];
} else {
imgCaption = imgAuthor;
}
self.labelImgCaption.text = imgCaption;
CGSize maximumLabelSize = CGSizeMake(296,9999);
CGSize expectedLabelSize = [imgCaption sizeWithFont:self.labelImgCaption.font
constrainedToSize:maximumLabelSize
lineBreakMode:self.labelImgCaption.lineBreakMode];
CGRect newFrame = self.labelImgCaption.frame;
newFrame.size.height = expectedLabelSize.height;
self.labelImgCaption.frame = newFrame;
}
-(void)populateWebView
{
NSString *htmlContentString = [DDUtilities createHTMLStringForArticleDetail:self.parsedNewsArticle];
[self.webView loadHTMLString:htmlContentString baseURL:nil];
}
-(void)checkSavedTextFontSize
{
self.textFontSize = [[DDUserDefaults getValueForKey:@"textFontSize"]integerValue];
if (self.textFontSize != 0) {
NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%d%%'",
self.textFontSize];
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
} else {
self.textFontSize = 100;
}
}
#pragma mark -
#pragma mark UIWebView Delegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
[[UIApplication sharedApplication] openURL:[request URL]];
return NO;
}
return YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[self checkSavedTextFontSize];
CGRect frame = webView.frame;
frame.size.height = 1;
webView.frame = frame;
CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
frame.size = fittingSize;
dispatch_async(dispatch_get_main_queue(), ^{
self.webView.frame = CGRectMake(frame.origin.x, self.labelImgCaption.frame.origin.y + self.labelImgCaption.frame.size.height + 5.0f, frame.size.width, frame.size.height);
self.contentView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.webView.frame.origin.y + self.webView.frame.size.height + 30.0f);
((UIScrollView*)self.view).contentSize = self.contentView.frame.size;
});
//[DDUtilities setImageView:self.image forLink:self.parsedNewsArticle.articleImgUrl placeholder:YES withActivityIndicator:self.activity];
}
-(void)webViewDidStartLoad:(UIWebView *)webView
{
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
}
#pragma mark -
#pragma mark MBProgressHUDDelegate methods
- (void)hudWasHidden
{
[self.mbProcess removeFromSuperview];
}
#pragma mark -
#pragma mark ParserDelegate methods
-(void)didFinishWithObject:(id)object
{
self.parsedNewsArticle = object;
[self loadData];
}
最佳答案
您创建一个 Controller (它有一个 View )。您将 View 指定为某个其他 View 的 subview 。就是这样。因此,ARC 将有助于销毁您不再使用的文章详细信息 Controller 。当它尝试调用委托(delegate)时,它已将自己设置为委托(delegate)的任何内容(如 Web View )现在都会崩溃。
解决方案:存储文章详细信息 Controller (添加一个强属性),以便在显示 View 时保留它。
或者,将 Controller 添加为智利 View Controller 。
关于ios - UIWebView loadHTMLString NSZombie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18129200/
我遇到了保留/释放问题。我的 View 非常复杂,因此我将 NSZombieEnabled 设置为 YES,并试图准确地找到哪个对象引起了我的悲伤。为了加快这个过程,我想知道是否有提示或技巧可以追踪僵
我在使用 cocos2d-iphone 的游戏中偶尔会出现 EXC_BAD_ACCESS 错误。 当发生这种情况时,Xcode 会执行以下任一操作: 显示 main.m 文件,没有堆栈回溯等。 显示
我在这里读到,启用 ARC 的 NSZombies 实际上会导致崩溃,而且我还读到它不可能是崩溃的原因。人们说它可能会因未在对象上调用 dealloc 的错误而导致崩溃。这是真的吗?现在仍然如此吗?我
突然之间,我一直在开发的一个应用程序不再向控制台输出调试信息,即使 NSZombie 已正确配置。我在 Xcode 4.5 上,并在 iOS 5 和 6 上试过这个。任何线索这里可能有什么问题? 最佳
所以我得到了一个 NSzombie,上面写着这个 -[__NSArrayI _cfTypeID]: 发送到释放实例的消息 知道那是什么吗?大概是一个数组,虽然我想如果它是一个 NS 类型它会说。 最佳
我正在尝试使用 NSZombie 调试 EXC_BAD_ACCESS 崩溃。尽管我的应用程序创建了许多大型对象,但启用 NSZombie 后,它们不会被释放,导致应用程序在几秒钟内崩溃。这意味着我什至
我看到有人建议在调试时将 NSZombieEnabled 设置为 true。什么是 NSZombie?它是一个框架吗?设置? 最佳答案 这是一个内存调试辅助工具。具体来说,当您设置 NSZombieE
我打开了僵尸,因为我遇到了一些崩溃。现在我在控制台中收到此错误。有谁知道这是什么意思吗? *** -[RoutineDayTableViewController 保留]:发送到已释放实例 0x7464
简而言之,我是NSZombies菜鸟。我只是开始尝试使用它们进行调试,因为直到现在,如果没有它们,我已经能够解决我所有的内存问题。 现在,我正在... [UIImage isKindOfClass:]
我目前正在开发一个严重依赖 Core Data 的应用程序。我使用导航 Controller 来插入和弹出 View 。我去的时候程序有时回到导航 Controller 的堆栈中崩溃,我收到错误(通常
我有一个 ios 电子邮件应用程序,一切正常,除了一个特定的用户帐户信息,我遇到与看起来像过度释放的对象相关的崩溃。 问题是,如果我启用 NSZombies(或使用 Instruments),则不会发
我正在开发一款连接到服务器并获取 JSON 数据的基本游戏。它在一些游戏中运行良好,但由于内存压力很快就崩溃了。我浏览了仪器并发现了一些相当令人不安的东西。 [[Class alloc]init] 实
当我使用 popViewController 时,我的应用程序崩溃了。使用 NSZombie 时我得到以下信息: 2011-07-15 13:20:03.334 Question[27412:207]
这个问题在这里已经有了答案: What is NSZombie? (4 个答案) 关闭 8 年前。
这绝对是内存崩溃,还是我应该寻找其他东西? Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRES
我正在制作一个新闻阅读应用。我有一个用作分页 Controller 的 ArticleDetailPagingVC。这有一个带有多个 ArticleDetailViewController 的 UIS
TL:DR 版本:我使用 NSZombieEnabled 查找 EXC_BAD_ACCESS 错误的来源,发现一个库的发布版本比保留版本多 1 个。我是否可以假设此库导致崩溃,或者该版本是否可以与另一
我的第一个应用程序即将完成,但我突然发现该应用程序导致内存泄漏。我发现了一些漏洞并修复了它们。现在没有泄漏,但令我惊讶的是,当启用 NSZombie 时,它显示了超过 4000 个主要来自框架的泄
我有一个 NSManagedObject 的子类,它有一些真正是枚举的“整数 32”属性。这些枚举在我的模型的 .h 文件中定义如下: typedef enum { AMOwningCompa
我试着在谷歌上搜索,但在试图弄清楚这意味着什么时几乎没有得到任何结果。我的控制台正在记录: objc[17048]: Class _NSZombie_GEOLatLng is implemented
我是一名优秀的程序员,十分优秀!