美好的一天,我正在学习Swift,需要一些帮助.
用户正在注册并选择他们的图像.在解雇图像选择器后,我想让ComposeViewController出现.
这是代码:
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: NSDictionary!) {
let pickedImage:UIImage = info.objectForKey(UIImagePickerControllerOriginalImage) as UIImage
//Scale Down Image
let scaledImage = self.scaleImageWith(pickedImage, and: CGSizeMake(100,100))
let imageData = UIImagePNGRepresentation(scaledImage)
let imageFile:PFFile = PFFile(data: imageData)
PFUser.currentUser().setObject(imageFile, forKey: "profileImage")
PFUser.currentUser().saveInBackgroundWithTarget(nil, selector: nil)
picker.dismissViewControllerAnimated(true, completion: nil)
//this is the line seems to have problem.
self.navigationController?.popToViewController(ComposeViewController, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
然后我收到这些错误:ComposeViewController.Type'不能转换为'UIViewController预期的成员名或类型名称后的构造函数调用
它有建议通过在ComposeViewController之后put()来修复,但是在修复之后它会发出更多错误.
希望有人能提供帮助.谢谢!:-)
我知道这是旧的,但它就像Saqib所说的那样,你不能弹出一个尚不存在的viewcontroller.
这里的很多答案似乎来自那些没有阅读你的问题的人,只有标题.我会在这里留下这些代码以防万一它可以帮助任何人.
let vcIndex = self.navigationController?.viewControllers.indexOf({ (viewController) -> Bool in
if let _ = viewController as? ComposeViewController {
return true
}
return false
})
let composeVC = self.navigationController?.viewControllers[vcIndex!] as! ComposeViewController
self.navigationController?.popToViewController(composeVC, animated: true)
Run Code Online (Sandbox Code Playgroud)
小智 7
let controllers = self.navigationController?.viewControllers
for vc in controllers! {
if vc is YourVC {
_ = self.navigationController?.popToViewController(vc as! YourVC, animated: true)
}
}
Run Code Online (Sandbox Code Playgroud)
导航控制器维护您正在推送的视图堆栈。它就像一个后进先出队列。
为了弹出到 ComposeViewController,该视图必须已存在于队列中,并且您应该可以引用它。
您将需要传递 ComposeViewController 的实例。为简单起见,您可以将该引用保存在 appdelegate 中。(不推荐这种方法)
| 归档时间: |
|
| 查看次数: |
13477 次 |
| 最近记录: |