AppDelegate 应该做多少事情?

发布于 2024-09-02 05:12:22 字数 750 浏览 8 评论 0原文

我正在设计一个相当大的应用程序,启动时它将与几个不同的服务器创建会话。由于他们正在创建一个可在应用程序的所有部分使用的会话,因此我认为在 App Delegate 中最好。

但问题是我需要在屏幕上显示会话进度。我计划在主菜单的底部有一个 UIToolBar,我不想用进度条覆盖它,而是覆盖它上面的 UIView。所以我看到它的方式我可以用几种不同的方式来实现。

1) 让应用程序代理建立会话并向主菜单类报告进度,以便它可以在进度栏中表示它(如果在单独的线程中创建会话,这样做会遇到任何问题吗?),

2)应用程序委托显示主菜单(带有一堆按钮和 UIToolBar 的 UIView)并让它跟踪和显示进度(我从未在应用程序委托中显示任何内容,但假设您可以执行此操作,但不推荐)或

3)应用程序代理只需按下主菜单并让 mainMenu 类创建会话并显示进度栏。

4)我认为另一种方法是在委托类中创建会话,并将委托设置为 mainMenu 而不是 self (AppDelegate),尽管我从未使用过 self 以外的任何东西,所以不确定这是否有效或者如果我能够关闭线程(也许通过调用 super?),因为它在 AppDelegate 中运行,而不是在类的委托中运行。

正如我之前所说,会话是在单独线程的类中创建的,因此它不会锁定 UI,我认为最好的方法是第一个,但是让它在单独的线程中运行是否会遇到问题,报告返回到应用程序委托,然后将该消息发送到 mainMenu 视图?

我希望一切都有意义,如果您需要任何进一步的说明,请告诉我。任何信息表示赞赏

干杯,

I'm designing quite a large App and on startup it will create sessions with a few different servers. As they are creating a session which is used across all parts of the app its something I thought would be best in App Delegate.

But the problem is I need the session progress to be represented on the screen. I plan to have a UIToolBar at the bottom of the main menu which I don't want to cover with the progress bar but cover the UIView above it.So the way I see it I could do it a few different ways.

1) Have the App Delegate establish the sessions and report the progress to the main menu class so it can represent it in the progress bar (will I have any issues doing this if the sessions are created in a separate thread?),

2) have the App delegate display the main menu (UIView with a bunch of buttons and UIToolBar) and have it track and display the progress (I have never displayed anything in the App Delegate but assume you can do this but its not recommended) or

3) have the App Delegate just push the main menu and have the mainMenu class create the sessions and display the progress bar.

4) I think the other way to do it is to create the sessions in a delegate class and have the delegate set to mainMenu rather than self (AppDelegate), although I've never used anything other then self so not sure if this will work or if I will be able to close the thread (through calling super maybe?) as its running in the AppDelegate rather than the delegate of the class.

As I've kinda said before the sessions are being created in a class in a separate thread so it wont lock the UI and I think the best way is the first but am I going to have issues having it running in a separate thread, reporting back to the app delegate and then sending that message to the mainMenu view?

I hope that all makes sense, let me know if you need any further clarification. Any information is appreciated

Cheers,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

负佳期 2024-09-09 05:12:22

据推测,连接状态将影响您的应用程序的功能。我可能会考虑连接管理器对象,它能够启动连接、维护其状态并在查询其状态时做出响应。就像单例对象将返回现有对象或创建并返回一个不存在的新对象一样,连接管理器甚至不需要“建立连接”方法,只需“获取句柄” - 如果连接不存在打开它可以尝试使之如此。

您还提到必须在主屏幕上报告状态。拥有一个管理器对象,能够在后台执行不确定时间的任务(打开与可能准备就绪、繁忙、遥远或完全损坏的主机的连接),然后向主线程报告进度,以便 UI 可以更新(记住,辅助线程中没有 UIKit 访问)似乎很理想,并且它也使您的视图保持独特。

Presumably the state of the connections will impact on your app's functionality. I would probably think in terms of a connections manager object which is able to initiate connections, maintain their state and respond when queried about their status. In the same way as a singleton object will return the existing object or create and return a new object of none exists, a connections manager doesn't even need a "make connection" method, just "get handle" - if the connection is not open it can try to make it so.

You also mention status must be reported on the main screen. Having a manager object that is able to do tasks of indeterminate time (opening a connection to a host that may be ready, busy, far away or just plain broken) in the background and then report progress to the main thread so the UI can be updated (remember, no UIKit access in secondary threads) seems ideal and it keeps your View distinct also.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文