最近,我终于重构了一个旧项目,并将所有的UIAlertViews和UIActionSheets转换为UIAlertControllers。但是,我开始收到客户反馈说有时UIAlertController的操作标题是空白的,就像这样:。我无法在我的设备上复现这个错误,你有任何关于可能原因的想法吗?
更新:我认为问题出现在这段代码中,可能主窗口的tintColor不是默认值,而UIAlertController会继承它?
更新:我认为问题出现在这段代码中,可能主窗口的tintColor不是默认值,而UIAlertController会继承它?
@implementation UIAlertController (WMC)
- (void)show:(BOOL)animated {
self.alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen
mainScreen].bounds];
self.alertWindow.rootViewController = [[UIViewController alloc] init];
id<UIApplicationDelegate> delegate = [UIApplication sharedApplication].delegate;
// Applications that does not load with UIMainStoryboardFile might not have a window property:
if ([delegate respondsToSelector:@selector(window)]) {
// we inherit the main window's tintColor
self.alertWindow.tintColor = delegate.window.tintColor;
}
// window level is above the top window (this makes the alert, if it's a sheet, show over the keyboard)
UIWindow *topWindow = [UIApplication sharedApplication].windows.lastObject;
self.alertWindow.windowLevel = topWindow.windowLevel + 1;
[self.alertWindow makeKeyAndVisible];
[self.alertWindow.rootViewController presentViewController:self animated:animated completion:nil];
}
@end