简体   繁体   English

如何将数据传递到UITabBarController

[英]How to pass data to a UITabBarController

My app features an UITabBarController , which brings up some views. 我的应用程序具有一个UITabBarController ,它可以显示一些视图。

In the app delegate, I have to pass a (custom) model to it. 在应用程序委托中,我必须将(自定义)模型传递给它。 Is the best way to do so is subclassing, or is there some better method? 这样做的最好方法是子类化,还是有更好的方法?

If I put the model (eg Notes) into my UITabBarController , how do I access it from view controllers? 如果我将模型(例如Notes)放入UITabBarController ,如何从视图控制器访问模型?

I'm not really sure why you would want to pass a different model to the UITabBarController. 我不太确定为什么要将不同的模型传递给UITabBarController。 The only thing tab bar controllers do really well is managing the tab bar. 标签栏控制器真正做的唯一一件好事就是管理标签栏。 Their "model" is basically a list of ViewControllers which they then present to the user if he taps a tab bar icon. 他们的“模型”基本上是ViewController的列表,如果用户点击标签栏图标,它们就会呈现给用户。

In the documentation Apple says the UITabBarController class is not intended for subclassing, but you could still do this if it were neccessary. 苹果在文档中说UITabBarController类不打算用于子类化,但是如果有必要,您仍然可以这样做。

But if you just want to do this because you have convenient access to the tab bar controller from within your other view controllers, then I'd recommend leaving the tab bar controller allone and implementing some sort of a NoteManager class (probably as a singleton) and simply using it from your other view controllers. 但是,如果您只是想这样做,因为您可以方便地从其他视图控制器中访问选项卡栏控制器,那么我建议您将选项卡栏控制器留给所有人,并实现某种NoteManager类(可能作为单例)并简单地从其他视图控制器中使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM