最近,我終於重構了一個傳統項目,並已將所有UIAlertViews
和UIActionSheets
轉換爲UIAlertControllers
。但我已經開始接受客戶的問題,他們說有時UIAlertController
操作標題是空白的。像這樣:UIAlertController顯示空白標題的UIAlertActions
我不能重現這個bug在我的設備,你有沒有對可能的原因,任何想法?
UPDATE:
我相信,這個問題被覆蓋的代碼,也許主窗口莫名其妙不是默認的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
你可以展示一些代碼,例如你試用過的東西! –
例如:http://hayageek.com/uialertcontroller-example-ios/ –