• <small id='NDCrG'></small><noframes id='NDCrG'>

    <tfoot id='NDCrG'></tfoot><legend id='NDCrG'><style id='NDCrG'><dir id='NDCrG'><q id='NDCrG'></q></dir></style></legend>

      <i id='NDCrG'><tr id='NDCrG'><dt id='NDCrG'><q id='NDCrG'><span id='NDCrG'><b id='NDCrG'><form id='NDCrG'><ins id='NDCrG'></ins><ul id='NDCrG'></ul><sub id='NDCrG'></sub></form><legend id='NDCrG'></legend><bdo id='NDCrG'><pre id='NDCrG'><center id='NDCrG'></center></pre></bdo></b><th id='NDCrG'></th></span></q></dt></tr></i><div id='NDCrG'><tfoot id='NDCrG'></tfoot><dl id='NDCrG'><fieldset id='NDCrG'></fieldset></dl></div>

        • <bdo id='NDCrG'></bdo><ul id='NDCrG'></ul>
      1. 在执行下一条语句之前,如何等待 NSURLConnection 委托完成?

        时间:2023-09-12

          • <bdo id='qEf6N'></bdo><ul id='qEf6N'></ul>

            <small id='qEf6N'></small><noframes id='qEf6N'>

              1. <legend id='qEf6N'><style id='qEf6N'><dir id='qEf6N'><q id='qEf6N'></q></dir></style></legend>
                    <tbody id='qEf6N'></tbody>

                  <tfoot id='qEf6N'></tfoot>
                  <i id='qEf6N'><tr id='qEf6N'><dt id='qEf6N'><q id='qEf6N'><span id='qEf6N'><b id='qEf6N'><form id='qEf6N'><ins id='qEf6N'></ins><ul id='qEf6N'></ul><sub id='qEf6N'></sub></form><legend id='qEf6N'></legend><bdo id='qEf6N'><pre id='qEf6N'><center id='qEf6N'></center></pre></bdo></b><th id='qEf6N'></th></span></q></dt></tr></i><div id='qEf6N'><tfoot id='qEf6N'></tfoot><dl id='qEf6N'><fieldset id='qEf6N'></fieldset></dl></div>

                1. 本文介绍了在执行下一条语句之前,如何等待 NSURLConnection 委托完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这很难搜索.我发现了一个类似的问题,iOS 5 等委托在填充表格之前完成?,但接受的答案是刷新表格视图",这对我没有帮助.我发现的其他结果往往是在 c# 中.

                  This has been a hard one to search. I found a similar question, iOS 5 Wait for delegate to finish before populating a table?, but the accepted answer was 'Refresh the table view,' and that does not help me. The other results I found tended to be in c#.

                  我有一个从 iPhone 流式传输到 Wowza 服务器的应用程序.当用户点击记录时,我生成一个唯一的设备 ID,然后将其发送到服务器上的 PHP 脚本,该脚本返回一个带有配置设置的 JSON 文档(包括 rtmp 转储链接).

                  I have an app that streams from iPhone to Wowza servers. When the user hits record, I generate a unique device id, then send it to a PHP script on the server that returns a JSON document with configuration settings (which includes the rtmp dump link).

                  问题是,委托方法是异步的,但我需要在我的 - (IBAction)recordButtonPressed 方法中的下一行代码之前获取配置设置,因为该代码是设置配置文件设置,然后根据这些设置进行记录.

                  The problem is, the delegate methods are asynchronous, but I need to get the config settings before the next lines of code in my - (IBAction)recordButtonPressed method, since that code is what sets the profile settings, and then records based on those settings.

                  我已经意识到我可以像现在一样在 -recordButtonPressed 中制作 NSURLConnection,然后在委托中继续设置代码inside方法 connectionDidFinishLoading (或者只是封装设置和从那里调用它的方法),但这牺牲了功能的连贯设计,这很糟糕.

                  I've realized I could make the NSURLConnection in -recordButtonPressed like I am currently, and then continue the setup code inside the delegate method connectionDidFinishLoading (or just encapsulate the setup and method call it from there) but that's sacrificing coherent design for functionality and that sucks.

                  难道没有一些简单的 waitUntilDelegateIsFinished:(BOOL)nonAsyncFlag 标志我可以发送给委托人,以便我可以进行从网络中提取数据的顺序操作吗?

                  Is there not some simple waitUntilDelegateIsFinished:(BOOL)nonAsyncFlag flag I can send to the delegator so I can have sequential operations that pull data from the web?

                  推荐答案

                  我已经意识到我可以像现在一样在 -recordButtonPressed 中创建 NSURLConnection,然后在委托方法 connectionDidFinishLoading 中继续设置代码(或者只是封装设置和从那里调用它的方法),但这会牺牲连贯的设计功能,这很糟糕.

                  I've realized I could make the NSURLConnection in -recordButtonPressed like I am currently, and then continue the setup code inside the delegate method connectionDidFinishLoading (or just encapsulate the setup and method call it from there) but that's sacrificing coherent design for functionality and that sucks.

                  您已经分析并了解了情况,并且完美地描述了可能的解决方案.我只是不同意你的结论.这种事情时有发生:

                  You have analyzed and understood the situation and you have described its possible solutions perfectly. I just don't agree with your conclusions. This kind of thing happens all the time:

                  - (void) doPart1 {
                      // do something here that will eventually cause part2 to be called
                  }
                  
                  - (void) doPart2 {
                  }
                  

                  您可以通过调用玩各种游戏,以使其更加优雅和通用,但我的建议是,不要与框架抗争,因为您所描述的正是异步的本质.(并且不要在主线程上使用同步请求,因为这会阻塞主线程,这是不行的.)

                  You can play various games with invocations to make this more elegant and universal, but my advice would be, don't fight the framework, as what you're describing is exactly the nature of being asynchronous. (And do not use a synchronous request on the main thread, since that blocks the main thread, which is a no-no.)

                  确实,在事件驱动的框架中,等到"这个概念本身就是一种诅咒.

                  Indeed, in an event-driven framework, the very notion "wait until" is anathema.

                  这篇关于在执行下一条语句之前,如何等待 NSURLConnection 委托完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:两个没有 segue 的 VC 之间的 Swift 委托 下一篇:在 Swift 中以编程方式设置 uitableview 的委托和数据源

                  相关文章

                2. <legend id='xftEH'><style id='xftEH'><dir id='xftEH'><q id='xftEH'></q></dir></style></legend><tfoot id='xftEH'></tfoot>
                3. <i id='xftEH'><tr id='xftEH'><dt id='xftEH'><q id='xftEH'><span id='xftEH'><b id='xftEH'><form id='xftEH'><ins id='xftEH'></ins><ul id='xftEH'></ul><sub id='xftEH'></sub></form><legend id='xftEH'></legend><bdo id='xftEH'><pre id='xftEH'><center id='xftEH'></center></pre></bdo></b><th id='xftEH'></th></span></q></dt></tr></i><div id='xftEH'><tfoot id='xftEH'></tfoot><dl id='xftEH'><fieldset id='xftEH'></fieldset></dl></div>

                      • <bdo id='xftEH'></bdo><ul id='xftEH'></ul>

                      <small id='xftEH'></small><noframes id='xftEH'>