为什么 UIAlertController 的标题没有更新?

Why does the title of the UIAlertController not get updated?

显示 UIAlertController 后,我启动了一个调用 timerLabel 的计时器。这应该更新 UIAlertControllers only 操作标题。 NSLog 显示标题实际上从 25 向下更改为 1。但是 UIAlertController 上的实际标题继续显示“25”。

我是否必须调用任何东西来更新标题才能显示?当我 运行 8.3 上的确切代码时,它可以工作,但是那是测试版,可能意味着它在实际发布时不会工作,所以我也需要它在非测试版 8.2 上工作。感谢任何建议。

NSTimer *buttonTimer;
UIAlertController *touchAdverts;
int timeStart;



-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];

timeStart = 25;
//inform user they need to touch adverts

touchAdverts = [UIAlertController alertControllerWithTitle:@"IMPORTANT" message:@"text to show user" preferredStyle:UIAlertControllerStyleAlert];
[touchAdverts addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:@"%i",timeStart] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//invalidate timer when button pressed
[buttonTimer invalidate];
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"hasHadTimedAlert"];
[[NSUserDefaults standardUserDefaults]synchronize];
}]];

//disables the action button from being interated with
[touchAdverts.actions[0]setEnabled:NO];
if ( ![[NSUserDefaults standardUserDefaults]boolForKey:@"hasHadTimedAlert"]) {
[self.view.window.rootViewController presentViewController:touchAdverts animated:YES completion:^{
//when alert is shown start timer to update the title of the alerts action
buttonTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerLabel) userInfo:nil repeats:YES];
}];
}



}


-(void)timerLabel{

if (timeStart >0) {
//countdown from timeStart
timeStart  -= 1;
//update the action button title each second to new timeStart value
[touchAdverts.actions[0] setTitle:[NSString stringWithFormat:@"%i",timeStart]];
NSLog(@"%@",[touchAdverts.actions[0] title]);
}else{
//When value of timeStart reaches 0 enable the action button and change title
[touchAdverts.actions[0] setEnabled:YES];
[touchAdverts.actions[0] setTitle:@"I have read & understood the above"];
}

}

目前,一旦显示视图,您就不能修改警报控制器视图的可见标题(尽管从您的实验来看,这似乎会在 iOS 8.3 最终版时开始工作)。但是你并不真的需要,因为用你自己的视图编写你自己的视图控制器很容易,它的外观和行为都像警报视图控制器的视图。当您这样做时,您就可以完全控制界面。所以如果你想让它在 iOS 8.2 及之前的版本中工作,我建议你这样做。