在我的应用程序中,数据来自网络服务,并且我已经实现了代码来显示活动指示器。我在 viewWillAppear() 中从 Web 服务获取数据。
问题是,当第一次调用 viewWillAppear() 时,指示器只显示一次,之后每当调用 viewWillAppear() 方法时,指示器就不会显示。
我的代码如下: -
-(void)viewDidAppear:(BOOL)animated
{
//Initializaing views for Acticity Indicators
loadingview = [[LoadingView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
Tickview= [[tickview alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
}
-(void)viewWillAppear:(BOOL)animated
{
Reachability *r = [Reachability reachabilityWithHostName:@"www.google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
if ((internetStatus == ReachableViaWiFi) || (internetStatus == ReachableViaWWAN))
{
[NSThread detachNewThreadSelector:@selector(startTheBackgroundJob) toTarget:self withObject:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Check Your Internet Connection. Internet Connection is not active" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
- (void)startTheBackgroundJob
{
[self performSelectorOnMainThread:@selector(loading) withObject:nil waitUntilDone:YES];
}
-(void)loading
{
//
//some database operations here..
//
//after that showing the activity indicator
[NSThread detachNewThreadSelector:@selector(threadAnimates:) toTarget:self withObject:nil];
//retriving data from web service..
[self retrieveData];
//than removing loadingview
[loadingview removeFromSuperview];
[loadingview setHidden:YES];
[NSThread detachNewThreadSelector:@selector(tickshow:) toTarget:self withObject:nil];
[self performSelector:@selector(tickhide:) withObject:nil afterDelay:2];
}
- (void) threadAnimates:(id)data
{
[self.view addSubview:self.loadingview];
[loadingview setHidden:NO];
}
-(void)tickshow:(id)sender
{
[self.view addSubview:Tickview];
[loadingview setHidden:NO];
}
-(void)tickhide:(id)sender
{
[Tickview removeFromSuperview];
[Tickview setHidden:YES];
}
当我设置断点进行复制时,指示器再次显示,但是当删除断点时,指示器不显示。
我已经在 .h 文件和项目中分别导入了用于加载视图和 tickview 的文件。
我已经尝试了很多,但无法得到解决方案。
请帮我。