gpt4 book ai didi

ios - 事件指示器未显示

转载 作者:行者123 更新时间:2023-12-01 18:26:56 27 4
gpt4 key购买 nike

在我的应用程序中,数据来自网络服务,我已经实现了代码来显示事件指示器。
我在 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 文件和项目中分别导入了用于加载 View 和 tickview 的文件。

我已经尝试了很多,但无法得到解决方案。

请帮我。

最佳答案

试试这个代码

-(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)];
[loadingview startAnimating];
[self.view addSubview:loadingview];

[self.view bringSubviewToFront: loadingview];
}

编辑:

也可以尝试下面的代码,只在 View 中添加事件指示器
        UIActivityIndicatorView *spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(10.0, 11.0, 25.0, 25.0)];
[spinningWheel startAnimating];
spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
[self.view addSubview:spinningWheel];
[spinningWheel release];

我希望这对你有帮助..

:)

关于ios - 事件指示器未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12743400/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com