无法出现微调器

发布于 2024-10-10 03:50:28 字数 675 浏览 0 评论 0原文

我想使用旋转器。但是,下面的代码不显示 旋转器,我不知道为什么。如何使这项工作有效?顺便说一句,它正在 从我创建的提交按钮调用。

//spinner declared in .h file
UIActivityIndicatorView   *aSpinner; 

//throw up spinner from submit btn we created
aSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:
    UIActivityIndicatorViewStyleWhiteLarge];

[self.view addSubview:aSpinner]; 
[aSpinner release]; 
[aSpinner startAnimating]; 

//send blocking request 
[request startSynchronous];

//get rid of spinner when finished delegate is fired
- (void)requestFinished:(ASIHTTPRequest *)request 
{ 
    NSLog(@"REQUEST FINISHED"); 
    [aSpinner stopAnimating]; 
    //[aSpinner release]; 
} 

I would like to use a spinner. But, this code below does not display a
spinner and I'm not sure why. How to make this work? BTW, It is being
called from a submit button I created.

//spinner declared in .h file
UIActivityIndicatorView   *aSpinner; 

//throw up spinner from submit btn we created
aSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:
    UIActivityIndicatorViewStyleWhiteLarge];

[self.view addSubview:aSpinner]; 
[aSpinner release]; 
[aSpinner startAnimating]; 

//send blocking request 
[request startSynchronous];

//get rid of spinner when finished delegate is fired
- (void)requestFinished:(ASIHTTPRequest *)request 
{ 
    NSLog(@"REQUEST FINISHED"); 
    [aSpinner stopAnimating]; 
    //[aSpinner release]; 
} 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你另情深 2024-10-17 03:50:29
//spinner declared in .h file
UIActivityIndicatorView  *aSpinner; 

也在头文件中添加一个属性:

@property (nonatomic, retain) UIActivityIndicatorView *aSpinner;

不要忘记在 .m 文件中综合!

//throw up spinner from submit btn we created
UIActivityIndicatorView *tempSpinner = [[UIActivityIndicatorView alloc]  initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
self.aSpinner = tempSpinner;
[tempSpinner release];

[self.view addSubview:self.aSpinner]; 
[self.aSpinner startAnimating]; 

//send blocking request 
[request startSynchronous];


//get rid of spinner when finished delegate is fire
- (void)requestFinished:(ASIHTTPRequest *)request { 
      NSLog(@"REQUEST FINISHED");
      [self.aSpinner stopAnimating]; 
}

在你的 dealloc 方法中你可以写: [aSpinner release];然而,这只是众多方法中的一种。

//spinner declared in .h file
UIActivityIndicatorView  *aSpinner; 

Add a property in the header file as-well:

@property (nonatomic, retain) UIActivityIndicatorView *aSpinner;

Don't forget to synthesize in .m file!

//throw up spinner from submit btn we created
UIActivityIndicatorView *tempSpinner = [[UIActivityIndicatorView alloc]  initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
self.aSpinner = tempSpinner;
[tempSpinner release];

[self.view addSubview:self.aSpinner]; 
[self.aSpinner startAnimating]; 

//send blocking request 
[request startSynchronous];


//get rid of spinner when finished delegate is fire
- (void)requestFinished:(ASIHTTPRequest *)request { 
      NSLog(@"REQUEST FINISHED");
      [self.aSpinner stopAnimating]; 
}

In your dealloc method you write: [aSpinner release]; This is however just one of many approaches.

荒路情人 2024-10-17 03:50:29

问题可能出在您要添加微调器的视图中。是否有能力并且具有显示活动指示器的尺寸? (例如UIBarButtonItems无法处理addSubview)

The problem could be in the view that you're adding the spinner to. Is is capable of, and does it have the dimensions to display the activity indicator ? (e.g. UIBarButtonItems cannot handle addSubview)

地狱即天堂 2024-10-17 03:50:28

如果您在显示微调器后立即调用一些阻塞代码,则 UI 将不会更新,因为它仅在主运行循环运行时更新。如果这确实是问题的根源,则当您注释掉 [request startSynchronous] 行进行测试时,应该会显示微调器。

解决方案是使用异步请求。委托代码看起来您​​已经这样做了,但另一方面,开始调用提到了同步操作。介意解释一下吗? (或者我忽略了什么?)

If you call some blocking code immediately after you display the spinner, the UI won’t get updated, since it only updates when the main run loop is running. If this really is the source of the problem, the spinner should show up when you comment out the [request startSynchronous] line for a test.

The solution would be to use an asynchronous request. The delegating code looks like you already do that, but on the other hand the start call mentions synchronous operation. Care to explain? (Or did I overlook something?)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文