iOS 子视图、SRP 和自定义事件
我是 iOS 开发新手,需要一些建议。我有一个类似聊天的应用程序。 UI 应该有一个用于将新消息发布到服务器的子视图和一个用于在表视图中查看消息的子视图。
我已在 Interface Builder 中将两个子视图构建为 XIB:s。但我不确定如何在主视图控制器上使用它们。我可以使用 IB 将自定义视图添加到设计图面吗?或者我需要以编程方式添加这些?
在这两个子视图之间发送消息或自定义事件的最佳方式是什么?我想让它们尽可能地分离。大多数情况下,我想在用户登录或注销时发送一个事件,以便 UI 可以对这些更改做出反应。我还希望带有消息的表视图知道何时从写入视图发布新消息。
// 约翰
I'm kind of new to iOS development and need some advice. I have a chat like app. The UI should have a child view for posting new messages to the server and one child view for viewing messages in a table view.
I've build both child views in Interface Builder as XIB:s. But I'm not sure how to use these on the main view controller. Can I use IB to add my custom views to the design surface? Or do I need to add these programmatically?
What is the best way to send messages or custom events between these two child views? I'd like to have them as decoupled as possible. Mostly I'd like to send an event when the user log on or off, so that the UI can react to these changes. I'd also like the table view with messages to know when a new messages is posted from the write view.
// Johan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了获取 xib 文件的内容,您必须首先向 NSBundle 类发送
loadNibNamed:owner:options:
消息来加载它。假设您有一个名为 CustomView 的 UIView 子类和 CustomView.xib 文件。在 xib 文件中,每个视图都有一个标签。您的 .h 文件如下所示:
这是关于如何将 .xibs 用于您的自定义 UIView 子类。如果您的应用程序类似于聊天应用程序,那么您必须以编程方式添加它们。
至于在两个自定义视图之间发送消息的最佳方式,您必须在每个视图中创建彼此的弱引用。
在一个
另一个
中,甚至在发生某些情况时向他们发送消息,
请告诉我这是否清楚。
In order to get the contents of a xib file you've got to load it first sending
loadNibNamed:owner:options:
message to NSBundle class.Consider you have a UIView subclass named CustomView and CustomView.xib file. In the xib file each view has a tag. Your .h file would look like:
This is about how to use .xibs for your custom UIView subclasses. If your app is like a chat then you'll have to add them programmatically.
As for the best way to send messages between two custom views, you'll have to create a weak reference to each other in each of them.
in one
in another
and just send them messages when some even happens
Let me know if this is clear.