我有一个需要修复以下崩溃详细信息的应用。流程是这样的,用户启动应用程序,新闻文章显示在uitableview
上,每个单元格都有一个文章详细信息。当用户单击任何单元格时,我们使用uipageviewcontroller
pageViewController.setViewControllers([newsDetails!], direction: UIPageViewControllerNavigationDirection.forward, animated: false, completion: nil)
上
如果文章仅在文本视图中显示,则向左和向右滑动控制器效果很好。但是,如果连续有2个Web视图文章,请向右滑动(从Web视图文章移至下一个Web视图文章),然后向左滑动(返回至Web视图文章),此应用crash log崩溃。
只是为了进行实验,我将数据放入了textview而不是uiwebview中,并且它仍然在相同的崩溃日志中崩溃,本文在其中使用了iframe标记。代码在这里:
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
//----------------------------------------------------------------------
// Returning the article's detail view controller for the previous index
print("VIEW CONTROLLER AFTER")
return articleDetailViewController(for: detailPageIndex()-1,fromDetail:false)
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
//------------------------------------------------------------------
// Returning the article's detail view controller for the next index
print("VIEW CONTROLLER BEFORE")
return articleDetailViewController(for: detailPageIndex()+1,fromDetail:false)
}
// We create a new instance of detail View Controller when ever a new VC is requested
func articleDetailViewController(for index: Int,fromDetail :Bool) -> MISNewsDetailViewController? {
let allNews:Bool
if(UserDefaults.standard.object(forKey: "IsAllNewsSelected") == nil || (UserDefaults.standard.object(forKey: "IsAllNewsSelected") as! String) == "YES"){
allNews = true
}else{
allNews = false
}
//--------------------------------------------
// If the index is out of bound, nil is return
if(allNews){
if (index == -1 || index >= (allArticles.count)) {
return nil
}
}else{
if (index == -1 || index >= (myArticles.count)) {
return nil
}
}
//---------------------------------------------------
// Getting the article object for the requested index
let article: MISArticle?
let detailViewController = storyboard?.instantiateViewController(withIdentifier: "MISNewsDetailViewController") as? MISNewsDetailViewController
let myAppDelegate = (UIApplication.shared.delegate as! AppDelegate)
if(myAppDelegate.isLaunchedFromWidget){
article = self.getTheWidgetSelectedArticleBaasedOnGlobalId();
}else{
if(allNews){
article = allArticles[index]
detailViewController?.isAllNewsPost = true
}else{
article = myArticles[index]
detailViewController?.isAllNewsPost = false
}
}
detailViewController?.mPost = article
detailViewController?.isRefreshPost = fromDetail
return detailViewController
}