Я создаю приложение и недавно обнаружил огромную утечку памяти, вызванную традиционными переходами. Поэтому я узнал о разматывании segue. Все работает просто отлично, если я просто использую:segueForUnwindingToViewController вызывает «Предупреждение: попытка представить <...> на <...>, который уже представляет <...>«
@IBAction func prepareForUnwindToMainFromFriends(segue: UIStoryboardSegue) {
}
Утечка памяти решена и «все просто потрясающе». Но это решение выглядит уродливым с точки зрения UI. Поэтому я реализовал эту функцию от this website. И немного изменил.
override func segueForUnwindingToViewController(toViewController: UIViewController, fromViewController: UIViewController, identifier: String?) -> UIStoryboardSegue {
return UIStoryboardSegue(identifier: identifier, source: fromViewController, destination: toViewController) {
let fromView = fromViewController.view
let toView = toViewController.view
if let containerView = fromView.superview {
let initialFrame = fromView.frame
var offscreenRect = initialFrame
var offscreenRectFinal = initialFrame
offscreenRect.origin.x += CGRectGetWidth(initialFrame)
offscreenRectFinal.origin.x -= CGRectGetWidth(initialFrame)
toView.frame = offscreenRect
containerView.addSubview(toView)
let duration: NSTimeInterval = 1.0
let delay: NSTimeInterval = 0.0
let options = UIViewAnimationOptions.CurveEaseInOut
let damping: CGFloat = 0.9
let velocity: CGFloat = 4.0
UIView.animateWithDuration(duration, delay: delay, usingSpringWithDamping: damping,
initialSpringVelocity: velocity, options: options, animations: {
toView.frame = initialFrame
fromView.frame = offscreenRectFinal
}, completion: { finished in
fromView.removeFromSuperview()
if let navController = toViewController.navigationController {
navController.popToViewController(toViewController, animated: false)
}
})
}
}
}
Но теперь я получаю сообщение об ошибке:
2015-05-12 08:47:31.841 PING0.4[4343:1308313] Warning: Attempt to present <NotificationViewController: 0x177030b0> on <PING0_4.ViewController: 0x16271000> which is already presenting <NotificationViewController: 0x1a488170>
И я заблокирован в моем приложении. Я могу перейти от VC1 к VC2, а затем вернуться к VC2, но потом я не могу снова вернуться к VC1. Похоже, я могу использовать этот сеанс только один раз.
У любого есть представление о том, что происходит?
Я предполагаю, что вы перепутали навигацию 'push' и' present'. Проверьте их внимательно – Silmaril
Этот вопрос: http: //stackoverflow.com/questions/22421845/ios-app-crash-on-multiple-segue-at-the-same-time-going-to-other-segue-while-o может быть полезно, если вы хотите ограничить множественный segue. – Pushparaj
@Quentin Malgaud Для получения дополнительной информации: http://stackoverflow.com/questions/19560198/ios-app-error-cant-add-self-as-subview – Pushparaj