我正在维护一个基于SDK 6.0的旧iOS项目。
该项目中有一个名为
-(void) showComboBox:(UIView*)view:withOptions:(NSDictionary*)options
的方法,用于显示下拉框。为了实现这个目标,它使用了在iOS8上已被弃用的UIActionSheet。
我的解决方案如下:
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来获得我想要的东西,但这是一个好方法吗?
view
是什么?它是任何视图控制器的子视图吗? - Kampaiview.nextResponder
是个坏主意?我已经进行了一些测试,似乎工作得很好。 - Don_Chen