【发布时间】:2015-02-22 07:38:59
【问题描述】:
我正在维护一个基于 SDK 6.0 的旧 iOS 项目。
这个项目的一个方法叫做
-(void) showComboBox:(UIView*)view:withOptions:(NSDictionary*)options
用于显示组合框。为了实现这个目标,它使用了 UIActionSheet,它在 iOS8 上已被弃用。
我的解决办法是这样的:
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber10_8) {
UIAlertController* alertController = [UIAlertController
alertControllerWithTitle:@"title"
message:@"message"
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* item = [UIAlertAction actionWithTitle:@"item"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
//do something here
//inform the selection to the WebView
...
[alertController dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[alertController dismissViewControllerAnimated:YES completion:nil];
}];
[alertController addAction:item];
[alertController addAction:cancelAction];
//I am not sure whether it's the right way
if ([view.nextResponder isKindOfClass:UIViewController.class]) {
UIViewController* vc = (UIViewController*)view.nextResponder;
[vc presentViewController:alertController animated:YES completion:nil];
}
这是一个合适的解决方案吗?
这是我最关心的: UIAlertController 需要添加到 UIViewController 但我只能获取 UIView 的指针,所以我使用 view.nextResponder 来获取我想要的,但是这是一个好方法吗?
【问题讨论】:
标签: ios objective-c uialertcontroller uiactionsheet