1

当我在我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

在根视图控制器中:

  #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;

}

我该如何解决这个问题?另外如何禁用网页视图的缩放?任何帮助,在此先感谢。

4

2 回答 2

1
return [dataViewController autorelease];

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

于 2013-01-21T04:53:06.263 回答
0

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

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

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

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

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

还可以启用 Zombie 对象并记录异常:

  1. 转到产品 -> 编辑方案
  2. 从左侧窗格中选择运行 YourApp.app。
  3. 在右窗格中选择诊断。
  4. “启用僵尸对象”和“记录异常”复选框。当应用程序崩溃时,这可能会在控制台上打印一些有用的信息。

希望这可以帮助您解决问题。

于 2013-01-14T13:11:20.613 回答