Swift非平衡调用

时间:2015-05-05 19:02:26

标签: ios swift uiviewcontroller uiimagepickercontroller

这一直困扰着我一段时间。我在UISplitViewController内有一个UITabBarController。主视图是TableView。当我点击一个单元格时,我会调出一个非常基本的视图控制器,只有UIButton居中。以下是视图控制器的代码:

class TestViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    @IBOutlet weak var button: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func buttonPressed(sender: AnyObject) {
        let pickerC = UIImagePickerController()
        pickerC.delegate = self

        pickerC.modalPresentationStyle = .Popover
        pickerC.popoverPresentationController?.sourceView = button as UIView
        pickerC.popoverPresentationController?.sourceRect = (button as UIView).bounds
        pickerC.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.Any
        self.presentViewController(pickerC, animated: true, completion: nil)//4
    }

    func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
        self.dismissViewControllerAnimated(true, completion: nil)
    }

    func imagePickerControllerDidCancel(picker: UIImagePickerController) {
       self.dismissViewControllerAnimated(true, completion: nil)
    }
}

如果单击取消或选择图像,则选取器控制器将正常解除。当我点击后退按钮返回TableView时出现问题,我收到:

Unbalanced calls to begin/end appearance transitions for <TestViewController: 0x7fb882a72380>.

TestViewController非常基本,为什么会发生这种情况呢?

3 个答案:

答案 0 :(得分:8)

如果您尝试在前一个事务(动画)正在进行时推送新的视图控制器,则会出现此问题。因此,请检查您的代码流并进行适当的更改。检查您的解雇并呈现视图动画。您可以使用属性setAnimation'YES / NO'解析此

设置动画:否,可能会解决您的问题

答案 1 :(得分:1)

对我来说,这个奇怪的问题是由于UISplitViewController

实现后跟随行而发生的
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
.
.
.
    // splitViewController.preferredDisplayMode = .PrimaryOverlay
.
.
.
    }

通过在didFinishLaunchingWithOptions中评论此行已解决。

答案 2 :(得分:0)

就我而言,我忘记删除情节提要文件。删除它后,此警告消失了。