如何从presentView控制器返回到RootViewController?

2023-12-05

我正在开发一个 iPhone 照片库应用程序,在我的应用程序中,我在图库中创建了一个文件夹,该图库文件夹显示在我的应用程序中,在使用时单击图像,它导航到下一个视图控制器,在其中他可以看到完整尺寸的图像,我在那里设置了垃圾按钮,以便用户可以删除该照片,我的垃圾按钮代码是:

@IBAction func btnTrash(sender: AnyObject) {

    let alert = UIAlertController(title: "Delete Image", message: "Are You Sure To delete this Image?", preferredStyle: .Alert)
    alert.addAction(UIAlertAction(title: "Yes", style: .Default, handler: {(alertAction)in
        //Delete Photo

        PHPhotoLibrary.sharedPhotoLibrary().performChanges({
            let request = PHAssetCollectionChangeRequest(forAssetCollection: self.assetCollection)
            request.removeAssets([self.photosAsset[self.index]])
            }, completionHandler: {(success, error )in
                NSLog("\nDeleted Image -> %@", (success ? "Success" : "Error"))
                alert.dismissViewControllerAnimated(true, completion: nil)

                self.photosAsset = PHAsset.fetchAssetsInAssetCollection(self.assetCollection, options: nil)
                if(self.photosAsset.count == 0){

                    // No photos Left
                    self.imgView.image = nil
                    println("No Image Left")

                    // Pop to root view controller
                    self.navigationController?.popToRootViewControllerAnimated(true)

                }
                if(self.index >= self.photosAsset.count){
                    self.index = self.photosAsset.count - 1
                }
                self.displayPhoto()
        })

    }))
    alert.addAction(UIAlertAction(title: "Cancle", style: .Cancel, handler: {(alertAction)in
    //Do not delete Photo

    self.dismissViewControllerAnimated(true, completion: nil)
    }))
    self.presentViewController(alert, animated: true, completion: nil)
}

我已经设置,如果没有剩余图像,则使用将导航到RootViewController用这行代码:

 self.navigationController?.popToRootViewControllerAnimated(true)

但这不起作用,当删除最后一张图像时,我得到一个窗口:

enter image description here

我的控制台出现:

2014-11-05 16:45:11.502 Photos Gallary App[3046:115145] Adding Image to Library -> Success
2014-11-05 16:45:15.285 Photos Gallary App[3046:115146] 
Deleted Image -> Success
No Image Left
2014-11-05 16:45:15.287 Photos Gallary App[3046:115146] *** Terminating app due to uncaught exception 'NSRangeException', reason: '0x7f95fb5ef980: index (18446744073709551615) beyond bounds (0)'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000100e4f3f5 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010297dbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x0000000100e4f32d +[NSException raise:format:] + 205
    3   Photos                              0x0000000100c5dd27 -[PHBatchFetchingArray objectAtIndex:] + 105
    4   Photos                              0x0000000100c63b92 -[PHFetchResult objectAtIndexedSubscript:] + 57
    5   Photos Gallary App                  0x0000000100b4d8d6 _TFC18Photos_Gallary_App9ViewPhoto12displayPhotofS0_FT_T_ + 694
    6   Photos Gallary App                  0x0000000100b50d93 _TFFFC18Photos_Gallary_App9ViewPhoto8btnTrashFS0_FPSs9AnyObject_T_U_FGSQCSo13UIAlertAction_T_U0_FTSbGSQCSo7NSError__T_ + 4243
    7   Photos Gallary App                  0x0000000100b4a6f6 _TTRXFo_dSboGSQCSo7NSError__dT__XFo_iTSbGSQS____iT__ + 38
    8   Photos Gallary App                  0x0000000100b4ed91 _TPA__TTRXFo_dSboGSQCSo7NSError__dT__XFo_iTSbGSQS____iT__ + 81
    9   Photos Gallary App                  0x0000000100b4a728 _TTRXFo_iTSbGSQCSo7NSError___iT__XFo_dSboGSQS___dT__ + 40
    10  Photos Gallary App                  0x0000000100b4a788 _TTRXFo_dSboGSQCSo7NSError__dT__XFdCb_dV10ObjectiveC8ObjCBooldGSQS___dT__ + 88
    11  libdispatch.dylib                   0x000000010541ccc6 _dispatch_call_block_and_release + 12
    12  libdispatch.dylib                   0x000000010543a7f4 _dispatch_client_callout + 8
    13  libdispatch.dylib                   0x0000000105425193 _dispatch_root_queue_drain + 1094
    14  libdispatch.dylib                   0x000000010542663c _dispatch_worker_thread2 + 52
    15  libsystem_pthread.dylib             0x00000001057d0ef8 _pthread_wqthread + 314
    16  libsystem_pthread.dylib             0x00000001057d3fb9 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

谁能告诉我发生了什么事以及解决方案是什么?


有什么方法self.displayPhoto()正在做?你想在 pop 之后调用它吗?看起来很奇怪。

尝试在后面的行添加“return”self.navigationController?.popToRootViewControllerAnimated(true)以确保执行在那里停止。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何从presentView控制器返回到RootViewController? 的相关文章

  • Google Cloud Messaging 显示成功消息但未发送 iOS

    所以我在使用 Google Cloud Messaging 时遇到了一个非常奇怪的问题 我遇到的问题是它正在成功注册设备 并且当发送消息时我会收到来自 Google 的成功消息 但设备永远不会收到任何消息 我从 GCM 得到的消息是 res
  • UITesting、XCTest 当前 ViewController 类

    简单的问题 我有一个按钮可以执行到下一个视图控制器的操作 我想写 UI XCTest 来告诉我它是否打开了我想要的视图控制器 UI 测试框架无法访问您的应用程序代码 这使得无法对实例进行类断言 你不能够directly告诉屏幕上的控制器的类
  • 在回调函数中调用目标c函数

    如何在回调函数中调用目标c函数 回调函数 static OSStatus inputRenderCallback void inRefCon AudioUnitRenderActionFlags ioActionFlags const Au
  • 如何组合两个 SwiftyJSON 对象

    我有一个 swiftyJSON 对象 例如 location http img http commentCount 0 timestamp 1432460217550 我希望能够向其附加另一个 swiftyJSON 对象 使其看起来像 lo
  • 使用 Quartz 创建 PDF 注释 (iOS)

    有人设法使用 Quartz 在现有 PDF 中编写自定义注释吗 我已经使用 CGPDFDocumentRef 等渲染了 PDF 现在工作正常 我成功地阅读了 Annots 字典 if CGPDFDictionaryGetArray page
  • iOS Swift 在后台下载大量小文件

    在我的应用程序中 我需要下载具有以下要求的文件 下载大量 例如 3000 个 小 PNG 文件 例如 5KB 逐个 如果应用程序在后台继续下载 如果图像下载失败 通常是因为互联网连接丢失 请等待 X 秒然后重试 如果失败Y次 则认为下载失败
  • Apple Developer 应用程序门户不再可以生成新的 Bundle Seed ID

    iOS 开发者门户中的新界面不再为您的应用程序 ID 提供 生成新的 按钮 取而代之的是 使用团队 ID 这将导致使用相同的种子 ID 任何人都知道为什么要进行更改以及您应该如何使用新的捆绑包种子 ID 随意补一些 不再可能生成新的种子 I
  • 在情节提要中将 Segue 拖至自身

    我想将一个 Segue 从我的视图控制器拖到其自身 所以我可以推送该特定视图控制器的 无限 实例 我知道如何在代码中执行此操作 即以编程方式实例化视图控制器 但是 我想尽可能使用 segues 我发现了一些在故事板中进行自我延续的 技巧 但
  • 将 Armadillo C++ 库导入 Xcode

    我是 Mac 用户 正在尝试安装和导入 C Armadillo 库 以下是我到目前为止所采取的步骤 1 我从其网站下载了犰狳库 2 我仔细阅读了下载文件中的 Readme txt 文件 解释了如何安装它 3 我使用CMake将犰狳下载文件制
  • 访问 google reader 的 Endpoints API 时出错

    我正在尝试在iPhone APP中实现google reader 到目前为止我已经成功收到了sid and auth 当我尝试使用以下命令调用 Endpoints API 时 问题就出现了GET 这是代码 ASIHTTPRequest re
  • 如何将CIFilter应用到UIView上?

    根据Apple docs 过滤属性CALayer不支持iOS 当我使用正在申请的应用程序之一时CIFilter to UIView即 Splice Funimate 和 Artisto 的视频编辑器 Videoshow FX 这意味着我们可
  • 使用 BGTaskScheduler 进行后台获取与调试模拟完美配合,但在实践中却不起作用

    我在 appDelegate 的 didFinishLaunchingWithOptions 中注册后台获取任务 BGTaskScheduler shared register forTaskWithIdentifier Backgroun
  • 带有 allowedEditing 的 UIImagePickerController 不允许平移裁剪

    我在这里看到这个问题 UIImagePicker 允许编辑卡在中心 https stackoverflow com questions 12630155 uiimagepicker allowsediting stuck in center
  • 如何在Sprite Kit中实现鼠标关节?

    我已经在 iOS 上用 Cocos2d Box2d 编写了拖放功能的工作实现 我需要将它移植到 Sprite Kit 逻辑非常基本 当用户触摸屏幕时 找到手指下的精灵 在找到的精灵和场景的物理体之间创建鼠标关节 将关节的目标设置为触摸位置
  • iOS Swift 和 reloadRowsAtIndexPaths 编译错误

    我与 xCode Swift 陷入僵局并刷新 UITableView 的单行 这条线有效 self tableView reloadData 而这条线没有 self tableView reloadRowsAtIndexPaths curr
  • 如何在 iOS 上固定证书的公钥

    在提高我们正在开发的 iOS 应用程序的安全性时 我们发现需要对服务器的 SSL 证书 全部或部分 进行 PIN 操作以防止中间人攻击 尽管有多种方法可以做到这一点 但当您搜索此内容时 我只找到了固定整个证书的示例 这种做法会带来一个问题
  • cordova插件条码扫描仪打不开扫描

    我的条形码扫描仪插件有问题 我不是天才 我不太了解如何编写网络应用程序 我使用phonegap和cordova 并且尝试制作一个网络应用程序 在单击链接后扫描条形码 我之前已经使用此命令行安装了该插件 cordova plugin add
  • 当 ViewController 从 UIStoryboard 实例化时,isMemberOfClass 返回 no

    我有一个 OCUnit 测试类 PatientTestViewControllerTests 下面是界面 interface PatientTestViewControllerTests SenTestCase property nonat
  • WKWebview 中的 iCLoud 文档选择器关闭容器视图

    我有一个 WKWebview 加载基于 Web 的 UI 我希望用户能够从其 iCloud 文档上传文件 我已授予正确的权限 并且可以浏览 iCloud 文档 但是 当我选择文件或单击取消按钮时 文档选择器视图也会关闭 WKWebview
  • 无需越狱即可检测iOS9上哪个应用程序处于前台

    我正在尝试记录用户在 iOS9 上的个人应用程序使用情况 我宁愿它不会使用越狱有限的解决方案 不言自明 在越狱手机上执行此应用程序的变体应该不难 https www andyibanez com create mobilesubstrate

随机推荐