UIAlertView 更新标题
Posted
技术标签:
【中文标题】UIAlertView 更新标题【英文标题】:UIAlertView update title 【发布时间】:2014-01-20 14:30:53 【问题描述】:我有一个 UIAlertView,它被声明为
-(UIAlertView *)waitingDialog
if (!_waitingDialog)
_waitingDialog = [[[UIAlertView alloc] initWithTitle:@"" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
return _waitingDialog;
show方法声明为:
-(void)showWaitingDialogWithText:(NSString *)text
[self.waitingDialog setTitle:text];
[self.waitingDialog show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(self.waitingDialog.bounds.size.width / 2, self.waitingDialog.bounds.size.height - 50);
[indicator startAnimating];
[self.waitingDialog addSubview:indicator];
[indicator release];
问题是:如何更新标题? 我尝试了以下但它不起作用。标题保持不变:
[self.waitingDialog setTitle:newTitle];
CGRect waitingFrame = self.waitingDialog.frame;
UILabel *alertLabel = [self.waitingDialog.subviews objectAtIndex:1];
CGRect waitingLabelFrame = alertLabel.frame;
[UIView animateWithDuration:0.15 delay:0.4 options:(UIViewAnimationCurveEaseIn) animations:^
[self.waitingDialog setFrame:waitingFrame];
alertLabel.frame = waitingLabelFrame;
completion:nil];
【问题讨论】:
【参考方案1】:试试这个
self.waitingDialog.title = @"new title";
[self.waitingDialog setNeedsDisplay];
【讨论】:
以上是关于UIAlertView 更新标题的主要内容,如果未能解决你的问题,请参考以下文章
如何在 ipad 应用程序的后台线程中显示 UIAlertView?
UIAlertView 具有用户提供的上下文和 [self autorelease]
检测 Internet 连接并显示 UIAlertview Swift 3