网页视图控制器与webview崩溃

时间:2013-01-14 08:52:16

标签: iphone ios objective-c ipad memory-management

我在contentviewcontroller中使用网页浏览,当我在页面之间滑动时,我的应用程序崩溃了 以下是我的代码:

contentviewcontroller.m

#import "ContentViewController.h"

@interface ContentViewController ()

@end

@implementation ContentViewController
@synthesize m_CtrlWebview,DocumentPath;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    m_CtrlWebview.scrollView.pagingEnabled=YES;
    m_CtrlWebview.scrollView.bounces=NO;
    m_CtrlWebview.scalesPageToFit=YES;
    m_CtrlWebview.backgroundColor=[UIColor clearColor];
    //m_CtrlWebview.scrollView.zooming=NO;
    m_CtrlWebview.scrollView.zoomScale=1.0;



    NSURL *url = [NSURL fileURLWithPath:DocumentPath isDirectory:NO];

    [m_CtrlWebview loadRequest:[NSURLRequest requestWithURL:url]];
}


-(void)dealloc
{
    [super dealloc];
}
- (void)viewDidUnload
{
    //[m_CtrlWebview stopLoading];
    [m_CtrlWebview release];
    [super viewDidUnload];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

在rootviewcontroller中:

  #pragma mark - UIPageViewControllerDataSource Methods

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
      viewControllerBeforeViewController:(UIViewController *)viewController
{
    NSUInteger currentIndex = [self.modelArray indexOfObject:[(ContentViewController *)viewController DocumentPath]];
    if(currentIndex == 0)
    {
        return nil;
    }

    ContentViewController *firstViewController = [self viewControllerAtIndex:currentIndex - 1];
    // ContentViewController *secondViewController = [self viewControllerAtIndex:x+1 ];


    return firstViewController;



}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
       viewControllerAfterViewController:(UIViewController *)viewController
{
    NSUInteger currentIndex = [self.modelArray indexOfObject:[(ContentViewController *)viewController DocumentPath]];
    if(currentIndex == self.modelArray.count-1)
    {
        return nil;
    }
    NSString *Path=[self.modelArray objectAtIndex:currentIndex + 1];
     if  (![[NSFileManager defaultManager] fileExistsAtPath:Path])
     {
        return nil; 
     }
    else
    {
        ContentViewController *firstViewController = [self viewControllerAtIndex:currentIndex + 1];

        return firstViewController;
    }

}

- (ContentViewController *)viewControllerAtIndex:(NSUInteger)index {

    if (([self.modelArray count] == 0) || (index >= [self.modelArray count])) {
        return nil;
    }
    ContentViewController *dataViewController;
    dataViewController = [[ContentViewController alloc]initWithNibName:@"ContentViewController" bundle:nil];

    dataViewController.DocumentPath = [self.modelArray objectAtIndex:index];
    return dataViewController;

}

我该如何解决这个问题?另外如何禁用Web视图的缩放?任何帮助,提前谢谢。

2 个答案:

答案 0 :(得分:1)

return [dataViewController autorelease];

- (ContentViewController *)viewControllerAtIndex:(NSUInteger)index中的上述一行解决了我的问题。

答案 1 :(得分:0)

从这段代码中可以确定应用程序崩溃的原因。 要更具体地捕获错误,请在Xcode中添加异常断点。 为Xcode 4.5执行此操作的步骤

  1. 在左窗格中选择“断点导航器”。

  2. 点按左下角的“+”按钮。

  3. 从弹出的菜单中,选择“添加例外断点”

  4. 当应用程序在执行此设置后崩溃时,请检查堆栈跟踪以查看您的任何功能是否在堆栈跟踪中。

  5. 还启用Zombie对象并记录异常:

    1. 转到产品 - >编辑方案
    2. 从左侧窗格中选择“运行YourApp.app”。
    3. 在右窗格中选择诊断。
    4. 选中“启用僵尸对象”和“记录例外”复选框。当app崩溃时,这可能会在控制台上打印一些有用的信息。
    5. 希望这可以帮助您解决问题。