English 中文(简体)
如何使MainThread等到某些同化行动完成之后?
原标题:How to make MainThread wait till some async action is done?

页: 1 当用户轮流使用装置时,需要将<条码>[表View reloadData]列入<条码>- 即将外向导向>。 重压 在我的案件中,数据是同步的。

www.un.org/spanish/ecosoc 我的理解是,再载荷在主线上运行,但焚烧了在我的案件中起作用的ForRowAtIndexPath。

因此,问题是如何把主要read等到<代码>。 UITableView s reloadData end.

最佳回答

如果你要求从Rotateto InterfaceOrientation中重载数据,则需要主线。 事实上,国际律师联合会的意见是安全的,只能从主线上处理(如果是出于某种原因,有人会要求从另一条路上重载Data)。

I think there is confusion relating to "asynchronous" as a term. Asynchronous callbacks for UI delegates like willRotateToInterfaceOrientation are called on the main thread. To be asynchronous does not necessarily mean a different thread (though running asynchronously "in parallel" does).

我建议阅读NSRunLoop的 Apple果文件。 它是“SOS”运行方式的一个组成部分,是评估方案者必须理解的。

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html

问题回答

You may use CFRunLoopRun to make your main thread wait until UITableView data is reloaded. After data is reloaded call CFRunLoopStop passing result of CFRunLoopGetMain as parameter.

You ll need to load your table s data in the background, then call UITableView s reloadData method.

您可以利用德国航天中心轻松地向背景点派遣负荷工作。 完成这项任务时,该工人已经向主人发回一个叫<代码>的栏目。 在这方面:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{

  ...
  dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  dispatch_async(queue, ^{

     // load your table data here
     [self loadMyTableData];

     // when done dispatch back to the main queue to load the table
     dispatch_queue_t mainQueue = dispatch_get_main_queue();
     dispatch_async(mainQueue, ^{

        [self.tableView reloadData];
      });
  });
  ...
}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签