2014-06-16 3 views
2

나는 dismissViewControllerAnimated (true, 완료 : {})를 사용하여 UIViewController를 닫으려고 시도하지만이를 시도 할 때 EXC_BAD_ACCESS를 얻습니다. (즉, 10 회 중 1 회 작동).dismissViewControllerAnimated 원인 EXC_BAD_ACCESS - 신속한

사용자 정의 transitionDelegate를 사용하고 설정하지 않을 때 작동합니다.

ListTransitionDelegate는 animators 및 presentationController를 반환합니다.

는 PresentationController 완료에 사용하려고하는 대신 nil 사용 {}의 PARAMS이

init(presentingViewController: UIViewController!, presentedViewController: UIViewController!, controllerStyle: SideControllerStyle, shortest: CGFloat) { 
    self.controllerStyle = controllerStyle 
    self.shortest = shortest 

    super.init(presentingViewController: presentingViewController, presentedViewController: presentedViewController) 

    self.dimmingView.backgroundColor = UIColor.blackColor() 

    var tapGesture = UITapGestureRecognizer(target: self, action: Selector("closePresented")) 
    dimmingView.addGestureRecognizer(tapGesture) 
} 

override func adaptivePresentationStyle() -> UIModalPresentationStyle 
{ 
    return UIModalPresentationStyle.OverFullScreen 
} 

override func shouldPresentInFullscreen() -> Bool 
{ 
    return true 
} 

override func presentationTransitionWillBegin() { 
    var containerView = self.containerView 
    self.dimmingView.frame = self.containerView.bounds 
    containerView.insertSubview(self.dimmingView, atIndex:0) 

    presentedViewController.transitionCoordinator().animateAlongsideTransition({context in 
     self.dimmingView.alpha = 0.5 
     }, completion:nil) 
} 

override func presentationTransitionDidEnd(completed: Bool) 
{ 
    if !completed { 
     self.dimmingView.removeFromSuperview() 
    } 
} 

override func dismissalTransitionDidEnd(completed: Bool) 
{ 
    self.dimmingView.removeFromSuperview() 
} 

override func dismissalTransitionWillBegin() { 
    presentedViewController.transitionCoordinator().animateAlongsideTransition({context in 
     self.dimmingView.alpha = 0 
     }, completion: nil) 
} 

func closePresented() { 
    var presenting = self.presentingViewController 

    presentedViewController.dismissViewControllerAnimated(true, completion: nil) 
} 

override func sizeForChildContentContainer(container: UIContentContainer!, withParentContainerSize parentSize: CGSize) -> CGSize { 
    var size : CGSize 

    switch self.controllerStyle { 
    case .Left, .Right: 
     size = CGSizeMake(self.shortest, parentSize.height) 

    case .Bottom, .Top: 
     size = CGSizeMake(parentSize.width, self.shortest) 

    default: 
     size = CGSizeMake(parentSize.width, parentSize.height) 
    } 

    return size 
} 

override func frameOfPresentedViewInContainerView() -> CGRect { 
    var frame : CGRect 
    var size = sizeForChildContentContainer(nil, withParentContainerSize: containerView.bounds.size) 

    switch self.controllerStyle { 
    case .Left: 
     frame = CGRectMake(containerView.bounds.size.width - size.width, 0, size.width, size.height) 

    case .Right: 
     frame = CGRectMake(0, 0, size.width, size.height) 

    case .Bottom: 
     frame = CGRectMake(0, containerView.bounds.size.height - size.height, size.width, size.height) 

    case .Top: 
     frame = CGRectMake(0, 0, size.width, size.height) 

    default: 
     frame = CGRectMake(0, 0, size.width, size.height) 
    } 
    return frame 
} 
+0

무엇이 잘못 되었나요? – Watsche

+0

Sry, 우연히 나는 글을 끝내기 전에 글을 올렸다. – einarnot

+0

[self dismissViewControllerAnimated : 예 완료 : 없음]; 이전보기로 이동해야합니다. – Watsche

답변

2

스위프트 1.1

것 같습니다. 예 : presentedViewController.dismissViewControllerAnimated(true, completion: {})

+0

이 나를 위해 작동하지 않습니다. –

4

구성 설정에서 좀비 개체를 사용 설정해보십시오. (변경 사항이 소스 컨트롤에 나타나지 않고 ARC없이 앱을 출시하고 싶지 않기 때문에 작업을 마친 후에는 꺼야합니다.)

-[_UILayoutGuide superview]: message sent to deallocated instance 0x1781ac6a0 
다음 바로보기 컨트롤러에이 코드를 해고 추가

deinit { 
    self.view.removeFromSuperview() 
} 

UILayoutGuide는 전용 자동 레이아웃 클래스입니다. 내가 버그라고 생각하고 (그런 식으로 제기했다.) 왜 해고당한 뷰 컨트롤러는 자동 레이아웃을 필요로 할까? 수퍼 뷰에서 클래스를 제거하면 할당 해제 된 후에 자동 할당 제약 조건에 액세스하는 것을 선제 적으로 방지 할 수 있습니다.

1

viewController를 닫기 전에 TransitioningDelegate nil을 설정해야합니다.

-1

동일한 문제가있었습니다. 클래스 변수를 선언해야했습니다.

class firstVC : UIViewController 
{ 
    let customTransitioninDelegate = customTransitioninDelegate(). 
... 

    //Then when created second view controller just assign it 
    -func xxx() 
    { 
     var secondVC = secondVC(); 
     secondVC.transitioningDelegate = customTransitioninDelegate; 
     self.presentViewController(secondVC, animated: true, completion: nil); 
    } 
} 
class secondVC: UIViewController 
{ 
... 
    func xxx() 
    { 
     if(self.presentingViewController != nil) 
     { 
      self.presentingViewController!.dismissViewControllerAnimated(true, completion: nil); 
     } 
    } 
} 

그리고 해고가 작동합니다.

+0

나를 위해 작동하지 않습니다. – einarnot

관련 문제