iPhone即时消息客户端设计问题
我正在 iphone 上编写 IM 客户端。// 帖子参考:#IMClient01。 这是我的初步设计:
(UIView*)LogInWindow; // to log in
(UITabBarController*) MainTabBarController;//have three tabs, namely:Contacts, Chats, My Profile
(UITableViewController*)ContactsController; //manages a list of contact/user
(UITableViewController*)ChatsController; //manages a list of chat history, each row is a chat with a different person
(UIViewController *)ChatController; //manages a chat/conversation with a single user.
与 iPhone 上的 Skype 一样,有两种方式开始对话/聊天。您可以通过点击联系人中的用户来与 Skype 用户聊天,或者如果有与该用户关联的聊天历史记录用户,您可以点击聊天中的聊天记录。如果上述场景映射到我的控制器类: 如果点击 ContactsController 中的单元格/行,则将 ChatController 推至顶部视图。 如果点击 ChatsController 中的单元格/行,则将 ChatController 推至顶部视图。
在两个推送操作中,它会是这样的:
[self.navigationController pushViewController:myChatController animated:YES];
我的第一个问题是 myChatController 应该是一个单例类吗?与在电脑上可以打开许多聊天窗口并且每个窗口管理与不同人的聊天不同,在iPhone中只有一个顶视图/窗口,因此只能显示一个聊天窗口?
我的第二个问题:如果 ContactsController 和 ChatsController 每个都有一个指向同一个 ChatController 实例的 ChatController 实例变量,这会是一个好主意吗?因此,当点击 ContactsController 或 ChatsController 中的单元格/行时,相同的 ChatController 实例会被推送到顶部视图以显示对话?
我的解释够清楚吗?如果有人能提供一些建议,我将非常感激。
I am writing an IM Client on iphone.// post ref: #IMClient01.
Here is my initial design of it:
(UIView*)LogInWindow; // to log in
(UITabBarController*) MainTabBarController;//have three tabs, namely:Contacts, Chats, My Profile
(UITableViewController*)ContactsController; //manages a list of contact/user
(UITableViewController*)ChatsController; //manages a list of chat history, each row is a chat with a different person
(UIViewController *)ChatController; //manages a chat/conversation with a single user.
As in Skype on IPhone, there are two ways to start a conversation/chat.You can either chat with a Skype user by tapping on the User from Contact or if there is a Chat History associated with the user, you can tap the Chat History in Chats. if the above scenario mapped to my controller classes:
If Tapping a cell/row in ContactsController then push ChatController to top view.
If Tapping a cell/row in ChatsController then push ChatController to top view.
In the two push operations, it would something like:
[self.navigationController pushViewController:myChatController animated:YES];
My first question is should myChatController be a singleton class? Unlike on computers,where you can have many chat windows open and each window manages a chat with a different person, in IPhone, there is only one top view/window, so only one chat window can be displayed?
My second question: Would this be a good idea if ContactsController and ChatsController each has a ChatController instance variable that points to the same ChatController instance? So when a cell/row in ContactsController or ChatsController is tapped, the same ChatController instance is pushed to the top view to display the conversation?
Am I explaining myself clear enough? I would really appreciate if someone can give some suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我对相关问题的回答,后退按钮从其来源处返回到不同的 UITableViewController,您需要完全放弃导航控制器并使用自定义代码管理视图的切换。
因此,您无需担心使用单例(无论如何,这在 Objective-c 中很难做到)。您也不需要 ContactsController 和 ChatsController 真正了解 ChatView,因为它们不会加载和显示它。相反,您将在自定义控制器中只拥有 ChatView 的单个属性,用于管理所有视图的交换和选项卡的移动。
一切都非常笨拙和复杂,但它会起作用。
In keeping with my answer to your related question, back button goes back to a different UITableViewController from where it came from, you need to abandon the navigation controller entirely and manage the switching of views with custom code.
As such you don't need to worry about using a singleton (which is hard to do in Objective-c anyway.) Nor to you need for the ContactsController and ChatsController to really know about the ChatView because they won't be loading and displaying it. Instead you will just have single attribute for the ChatView in the custom controller that manages the swapping out of all the views and the shifting of tabs.
All very ungainly and complicated but it will work.