Can’t get a spinner to appear

爱⌒轻易说出口 提交于 2019-12-04 10:17:52

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?)

//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.

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)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!