Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios PageViewController:SetViewController使我的应用程序崩溃_Ios_Swift_Uipageviewcontroller_Crash - Fatal编程技术网

Ios PageViewController:SetViewController使我的应用程序崩溃

Ios PageViewController:SetViewController使我的应用程序崩溃,ios,swift,uipageviewcontroller,crash,Ios,Swift,Uipageviewcontroller,Crash,当我运行我的应用程序时,我注意到setViewController方法会导致内存链接并使我的应用程序崩溃。我已经针对这个问题工作了几个小时,并尝试在web上查找,发现了一个,其中提到将我的setViewController方法放入dispatch\u async(dispatch\u get\u main\u队列)但这会终止应用程序,我在控制台中遇到以下错误: 2015-12-26 19:41:55.596哈里什·耶拉[4663:132796]XPC连接中断 2015-12-26 19:41:5

当我运行我的应用程序时,我注意到
setViewController
方法会导致内存链接并使我的应用程序崩溃。我已经针对这个问题工作了几个小时,并尝试在web上查找,发现了一个,其中提到将我的
setViewController
方法放入
dispatch\u async(dispatch\u get\u main\u队列)
但这会终止应用程序,我在控制台中遇到以下错误:

2015-12-26 19:41:55.596哈里什·耶拉[4663:132796]XPC连接中断 2015-12-26 19:41:55.596 Harish Yerra[4663:132797]由于没有系统应用程序而终止

iPhone然后完全重新启动并返回主屏幕

我已尝试注释掉
setViewController
方法,我的应用程序加载页面视图控制器的第一页时效果良好,然后当我滚动到下一页时,它再次崩溃,出现以下错误:

*在-[\u UIQueuingScrollView\u replaceView:updateingcontents:adjustContentInsets:animated:],/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit\u Sim/UIKit-3512.30.14/\u uiqueuiuingScrollView.m:377中断言失败
2015-12-26 19:31:55.058 Harish Yerra[4381:123817]*
由于未捕获的异常“NSinternalinconsistenceexception”而终止应用程序,原因:“无效参数不满足:[视图计数]==3” ***第一次抛出调用堆栈: ( 0 CoreFoundation 0x000000010e411e65异常预处理+165 1 libobjc.A.dylib 0x00000001105b0deb objc_异常_抛出+48 2 CoreFoundation 0x000000010E411CA+[N异常提升:格式:参数:][106 3基金会0x000 000 010EA824DE-[ NSRealStutsHuffer-HooRealRuleIn方法:对象:文件:文件号:描述:] + 198 4 UIKit 0x000000010f8d5575-[\u UIQueuingScrollView\u ReplaceView:更新内容:调整内容插图:动画:][289 5 UIKit 0x000000010f8d949d-[u UIQueuingScrollView\u didScrollWithAnimation:force:][1350 6 UIKit 0x000000010f8d4701-[\u UIQueuingScrollView布局子视图]+176 7 UIKit 0x000000010f1444a3-[UIView(CALayerDelegate)布局层的子层:+703 8夸脱核心0x000000010ef4959a-[CALayer layoutSublayers]+146 9夸脱核心0x000000010ef3de70(如果需要)ZN2CA516层布局交易+366 10夸脱核心0x000000010ef3dcee\u ZN2CA58层布局\u和\u显示\u如果需要\u 11事务处理+24 11 QuartzCore 0x000000010ef32475_ZN2CA7Context18提交交易PNS_11交易+277 12夸脱芯0x000000010ef5fc0a_Zn2Ca11交易承诺+486 13夸脱核心0x000000010ef6e9f4 _ZN2CA7Display11DisplayLink14调度项目Y+576 14 CoreFoundation 0x000000010e371c84\uuu CFRUNLOOP\u正在调用\u OUT\u到\u计时器\u回调\u函数+20 15 CoreFoundation 0x000000010e371831\uu CFRunLoopDoTimer+1089 16 CoreFoundation 0x000000010e333241\uuu CFRunLoopRun+1937 17 CoreFoundation 0x000000010e332828 CFRunLoopRunSpecific+488 18图形服务0x0000000112219ad2 GSEventRunModal+161 19 UIKit 0x000000010f08d610 UIApplicationMain+171 20 Harish Yerra 0x000000010d813efd干管+109 21 libdyld.dylib 0x00000001115f092d启动+1 ) libc++abi.dylib:以NSException类型的未捕获异常终止 (lldb)

我将为我的
viewDidLoad
提供代码,但是如果您需要整个页面viewcontrollerdatasource的代码,请告诉我,我将提供它。非常感谢你的帮助

    override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    self.pageViewController = harishStoryboard.instantiateViewControllerWithIdentifier("HarishPageViewController") as! UIPageViewController
    self.pageViewController.dataSource = self
    let initialViewController = harishStoryboard.instantiateInitialViewController() as! HarishIntroduction
    let viewController = NSArray(object: initialViewController)
    dispatch_async(dispatch_get_main_queue(), {
        self.pageViewController.setViewControllers(viewController as? [UIViewController], direction: .Forward, animated: false, completion: nil)
    })
    self.pageViewController.view.frame = CGRectMake(0, 100, self.view.frame.size.width, self.view.frame.size.height-100)
    self.addChildViewController(pageViewController)
    self.view.addSubview(self.pageViewController.view)
    self.pageViewController.didMoveToParentViewController(self)
}

如果要创建UIPageViewController?你可以在你的Xcode中找到最好的细节!只需单击“基于页面的应用程序”按钮,而不是“单视图应用程序”!苹果已经在Xcode 7.2中提供了最新的变化和大量的代码!祝你好运

好的,非常感谢大家的帮助。然而,我想我发现了我的问题所在。我的第一个错误是没有将
setViewControllers
方法放入
dispatch\u get\u main\u queue()
。还有,帮了我很多忙。它基本上告诉我在
viewController上使用
if
语句。在
pageViewController
beforeViewController
afterViewController
方法的数据源方法中,这是一种class
方法,用于确定要正确导航到哪个视图


我真的希望这篇文章能帮助任何和我有同样问题的人。不过,谢谢你的帮助

是的,但我的应用程序只有一部分是PageViewController,而不是全部。此外,我已经创建了我的应用程序的很大一部分,所以重新开始会很痛苦。但是,是否可以将一个Xcode项目导入另一个Xcode项目?@Harish您可以在另一个项目中选择基于页面的应用程序,并将该视图控制器复制并粘贴到当前的Xcode项目中project@AjinkyaPatil好的,我会试试,但唯一的问题是我已经完成了整个PageViewController的大部分设置。因此,我真的很想尝试解决这个问题,如果没有解决方案,我将使用苹果提供的模板。你是在真正的设备上运行的吗在真实设备或模拟器上运行时也会发生同样的情况。请在bugreport.apple.com上提交一个bug。在任何情况下,您的应用程序都不应使系统崩溃NSInternalInconsistencyException',原因:'无效参数不满足:[views count]==3'表示需要3个视图。所以