我遇到了这个错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing the same view controller instance more than once is not supported
如何检查控制器是否已经存在于堆栈中,而不是将该控制器推入堆栈而是移动到该控制器?
以下是一些代码,我正在基于选项卡选择推送一个控制器:
func tabSelected(tab: String) {
switch tab{
case "payment":
mainNavigationController.popToViewController(myAccountViewController, animated: true)
break
case "delivery":
mainNavigationController.pushViewController(deliveryViewController, animated: true)
break
case "service":
mainNavigationController.pushViewController(serviceViewController, animated: true)
break
case "profile":
mainNavigationController.pushViewController(profileViewController, animated: true)
break
default:
break
}
}
mainNavigationController.viewControllers.contains { $0 == controller }
。 - Ian MacDonald