UIActivityIndi​​catorView不在UIAle

UIActivityIndi​​catorView不在UIAle

本文介绍了UIActivityIndi​​catorView不在UIAlertView上显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个iOS应用程序,并且必须使用微调器显示UIAlertView.有时,当我尝试将微调器添加到警报的中心时出了点问题,通常是在此警报之前有另一个警报(这不完全是规则,但这是我注意到它失败的方式)).

I am writing an iOS app, and I have to display a UIAlertView with a spinner. Sometimes, something goes wrong when I try to add the spinner in the center of the alert, usually when there was another alert right before this one (not exactly a rule, but this is how I noticed it fails).

我通过延迟微调器的创建部分解决了该错误.这是我的操作方式( alert 是UIAlertView的成员):

I partly solved this bug by delaying the creation of the spinner. Here is how I do it (alert is a member UIAlertView) :

此代码在viewDidLoad中:

This code is in viewDidLoad :

alert = [[[UIAlertView alloc] initWithTitle:@"Loading..." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles: nil] autorelease];

[alert show];

[self performSelector:@selector(addSpinner) withObject:nil afterDelay:0.5f];

这是我的 addSpinner 函数:

- (void) addSpinner{

    UIActivityIndicatorView *indicator2 = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    indicator2.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);

    [indicator2 startAnimating];
    [alert addSubview:indicator2];
    [indicator2 release];
}

此解决方案每次都有效,但是我真的不喜欢它的完成方式.尽管在警报弹出后半秒钟显示微调框并没有太大的干扰,但必须有更好的方法来处理此问题.我不是iOS方面的专家,也不是高级程序员,但是我不能使用事件吗?类似于当警报实际显示时,请执行addSpinner函数"?我不知道如何执行此操作,因此在网络上找不到太多帮助...

This solution is working every time, but I really don't like how it's done. Even though showing the spinner half a second after the alert pops up is not so much disturbing, there must be a better way to handle this. I am not an expert in iOS, nor am I a senior programmer, but can't I use an event ? Something like "when the alert is actually displayed, go the addSpinner function" ? I have no idea how to do this, and could not find much help on the web...

希望有人可以帮助我!谢谢.

Hope someone can help me ! Thanks.

推荐答案

您可以使用 https://github.com/jdg/MBProgressHUD .

对于警报内的微调框,您可以使用以下方法.

and for spinner within alert, you can use these methods.

-(void)startLoading
{
    alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Please Wait..." delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];

    UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
    progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
    [alert addSubview:progress];
    [progress startAnimating];
    [progress release];
    [alert show];
}
-(void)stopLoading
{
    [alert dismissWithClickedButtonIndex:0 animated:YES];
    [alert release];
}

这篇关于UIActivityIndi​​catorView不在UIAlertView上显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 10:03