由於在iOS9中棄用警報視圖,我很難通過NSObject類 顯示警報,因爲在UIAlertView中有一種方法可顯示警報[objaler show];但在iOS 9中顯示警報 我們必須使用presentViewController,以便任何人都可以告訴我如何在nsobject類中顯示警報視圖控制器。如何在iOS9的NSObject類中調用UIAlertviewController?
我想在NSObject類來調用的代碼如下:
UIAlertController *alert= [UIAlertController
alertControllerWithTitle:@"Login"
message:@"Enter your credentials here"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"Done" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action){
//Do Some action here
}];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSLog(@"cancel btn");
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:ok];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];
}
我的問題是我想打電話給在NSObject類。 如何做到這一點?
爲什麼不嘗試使用NSNotification?在您的NSObject類上,發佈通知,然後在UIViewController類中添加一個觀察者,該類將調用選擇器來顯示您的UIAlertAction。 –
@JohnRusselUsi好主意。 –