不同导航堆栈中的变量
抱歉,如果我的问题与标题不相符,但我认为确实如此: 我有一个带有导航控制器和 3 个视图的应用程序。这是一个连接到服务器并与朋友交谈的应用程序。 问题是,我的 rootViewController(登录屏幕)调用第二个视图,即朋友列表。单击列表中的朋友会将您带到第三个视图,即聊天屏幕本身。 我想,当用户登录(rootview)时,将使用的用户名存储在变量中,这样我就可以在第三个视图(聊天屏幕)上使用它,这样当他发送消息时,上面可以有他的名字,在从服务器检索信息时,我也可以使用他的名字作为参数。 顺便问一下,SQLite 是保存消息和用户的最佳方式吗?我害怕核心数据=/
Sorry if my question does not match the title, but i think it does:
I have an app with a navigation controller and 3 views. It's an app where you connect to a server and talk with friends.
The thing is, my rootViewController, the login screen, calls the second view witch is the friends list. clicking in a friend on the list takes you to the third view, the chat screen itself.
I wanted to, when the user logs in (rootview), to store the user name used in a variable, so i could use it on the third view, the chat screen, so when he sends a message it can have his name on it, and while retrieving info from server, i can use his name as a parameter too.
By the way, is SQLite the best way to save messages and users? I am afraid of Core Data =/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了保持松散耦合,我会考虑在实例化每个
UIViewController
子类时仅传递userName
。 (也使单元测试更容易)例如,
不要害怕核心数据,那里有很多优秀的书籍。
To keep things loosely coupled I would consider just passing along the
userName
when instantiating eachUIViewController
sub class. (Makes unit testing easier as well)e.g.
Don't be afraid of core data there are plenty of excellent books out there.
核心数据并没有那么糟糕。 这是我用来开始使用 Core Data 的指南。一旦你了解了一切是如何运作的,事情其实并没有那么糟糕。
如果您愿意,可以使用 SQLite,但它需要大量代码。 Core Data 使用起来要简单得多。
Core data is not that bad. This is the guide I used to get started with Core Data. Once you wrap your head around how everything works it really isn't that bad.
If you wanted to you could use SQLite, but it's a lot of code. Core Data is much simpler to use.