【发布时间】:2012-07-10 07:33:07
【问题描述】:
我正在编写一个 iOS 应用程序,我必须显示一个带有微调器的 UIAlertView。 有时,当我尝试在警报中心添加微调器时会出现问题,通常是在此之前有另一个警报时(不完全是规则,但这就是我注意到它失败的原因)。
我通过延迟微调器的创建部分解决了这个错误。这是我的做法(alert 是 UIAlertView 的成员):
这段代码在 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 函数”之类的东西?我不知道该怎么做,在网上找不到太多帮助...
希望有人可以帮助我!谢谢。
【问题讨论】:
标签: iphone objective-c ios uialertview