我为IOS应用程序开发了登录,注册和其他几个屏幕。现在,我正在尝试为我的应用程序构建仪表板屏幕(与Facebook的新闻提要类似,请考虑使用它),但是在情节提要中创建UI时遇到了困难。另外,如果帖子中没有Image,那么我希望UITableView单元格通过将UIImageView的高度设置为零来减小其大小,但是它对我不起作用。总体而言,对于我的仪表板屏幕,我正在考虑从代码本身构建UI。现在我有以下问题:
是否可以将故事板用于某些屏幕,而不用于其他屏幕?
如果是,那么如何从具有情节提要的屏幕(例如我的登录屏幕)导航到没有情节提要的屏幕(例如我的仪表板屏幕)。
谢谢。
最佳答案
使用情节提要:首先将ViewController嵌入到NavigationController中
使用定序
数据传输代码:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let detailController = segue.destination as? SecondViewController
detailController.object = self.object
}
不带句号:
如果两个ViewController都在同一个情节提要中
func foo() {
let secondViewController = self.storyboard?.instantiateViewControllerWithIdentifier("secondViewController") as? SecondViewController
self.navigationController?.pushViewController(secondViewController!, animated: true)
}
如果两个SecondViewController都在不同的情节提要中
从捆绑包中获取情节提要,然后导航至该情节提要
func foo() {
let fooStoryboard = UIStoryboard.init(name: "Foo", bundle: Bundle.main)
let secondViewController = self.storyboard?.instantiateViewControllerWithIdentifier("secondViewController") as? SecondViewController
self.navigationController?.pushViewController(secondViewController!, animated: true)
}
(无情节提要):
将LoginViewController嵌入为rootViewController,以便进行导航。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let fooStoryboard = UIStoryboard.init(name: "Foo", bundle: Bundle.main)
let loginViewController = fooStoryboard.instantiateViewControllerWithIdentifier("loginViewController") as? LoginViewController
let navigationController = UINavigationController(rootViewController: loginViewController)
self.window?.rootViewController = navigationController
return true
}
现在,您可以从LoginViewController像上面建议的那样以编程方式推送。
关于ios - 有和没有 Storyboard的iOS开发,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51222486/