在iOS开发中,模态(Modal)和非模态(Non-Modal)是两种常见的视图控制器(ViewController)展示方式。它们的基础概念、优势、类型、应用场景以及遇到的问题和解决方法如下:
模态展示:
非模态展示:
模态展示的优势:
非模态展示的优势:
模态展示的类型:
非模态展示的类型:
pushViewController:animated:
方法。selectedIndex
属性。模态展示的应用场景:
非模态展示的应用场景:
问题1:模态视图控制器无法关闭
问题2:非模态视图控制器返回时数据丢失
prepare(for:sender:)
方法传递数据。prepare(for:sender:)
方法传递数据。UserDefaults
、Core Data等持久化存储数据。模态展示示例:
let modalVC = ModalViewController()
modalVC.modalPresentationStyle = .fullScreen
self.present(modalVC, animated: true, completion: nil)
非模态展示示例:
let detailVC = DetailViewController()
self.navigationController?.pushViewController(detailVC, animated: true)
通过以上内容,你应该对iOS中的模态和非模态展示有了全面的了解,并能根据具体需求选择合适的展示方式。
领取专属 10元无门槛券
手把手带您无忧上云