- (voID)vIEwWillAppear:(BOol)animated { [super vIEwWillAppear:animated]; UIApplication* app2 = [UIApplication sharedApplication]; app2.networkActivityIndicatorVisible = YES; [self loadSources]; // Loads data in table vIEw app2.networkActivityIndicatorVisible = NO; }
张志贤
解决方法 由于NetworkActivityIndicatorVisible可以在连接仍处于活动状态时从多个点设置,因此您需要跟踪启用/禁用它的调用数.以下UIApplication类别仅使用静态变量:// file UIApplication+NetworkActivity.h@interface UIApplication (NetworkActivity)- (voID)showNetworkActivityIndicator;- (voID)hIDeNetworkActivityIndicator;@end// file UIApplication+NetworkActivity.m#import "UIApplication+NetworkActivity.h"static NSInteger activityCount = 0;@implementation UIApplication (NetworkActivity)- (voID)showNetworkActivityIndicator { if ([[UIApplication sharedApplication] isstatusbarHIDden]) return; @synchronized ([UIApplication sharedApplication]) { if (activityCount == 0) { [self setNetworkActivityIndicatorVisible:YES]; } activityCount++; }}- (voID)hIDeNetworkActivityIndicator { if ([[UIApplication sharedApplication] isstatusbarHIDden]) return; @synchronized ([UIApplication sharedApplication]) { activityCount--; if (activityCount <= 0) { [self setNetworkActivityIndicatorVisible:NO]; activityCount=0; } }}@end
现在在您的客户端代码中导入UIApplication NetworkActivity.h并调用
// on connection started:[[UIApplication sharedApplication] showNetworkActivityIndicator];// on connection finished:[[UIApplication sharedApplication] hIDeNetworkActivityIndicator];
如果您担心指示灯只闪烁一秒钟,则不需要后台处理.只需调用[self performSelector:@selector(loadSources)withObject:Nil afterDelay:0.1],这样UI线程就有时间在阻塞主线程之前启动网络指示器动画.
总结以上是内存溢出为你收集整理的iphone – networkActivityIndicatorVisible全部内容,希望文章能够帮你解决iphone – networkActivityIndicatorVisible所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)