This method registers with the runloop of its current context, and depends on that runloop being run on a regular basis to perform correctly. One common context where you might call this method and end up registering with a runloop that is not automatically run on a regular basis is when being invoked by a dispatch queue. If you need this type of functionality when running on a dispatch queue, you should use dispatch_after and related methods to get the behavior you want.
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
//1.直接调用会阻塞主线程
// [self handelData];
// //记录登录时间
// [AccountInfo sharedAccount].LoginDate=[NSDate date];
// [self.sideBarController setShowSideView:YES];
//2.通过performSelector调用
// [self performSelector:@selector(handleData) withObject:nil afterDelay:0.1];
//3.GCD
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
<code class="java comments"> //这个selector不会执行</code><div class="line number22 index21 alt1"><code class="java spaces"> //</code><code class="java plain">[self performSelector:</code><code class="java color1">@selector</code><code class="java plain">(testDelay) withObject:nil afterDelay:</code><code class="java value">3</code><code class="java plain">];</code></div> [self dd];
dispatch_async(dispatch_get_main_queue(), ^{
//记录登录时间
[AccountInfo sharedAccount].LoginDate=[NSDate date];
[self.sideBarController setShowSideView:YES];
});
});
}
- (void)dd{
dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, 1*NSEC_PER_SEC);
dispatch_after(time, dispatch_get_main_queue(), ^{
[self <code>handelData</code>];
});
}