Я поддерживаю старый проект iOS, основанный на SDK 6.0.
Метод этого проекта под названием
-(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 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, чтобы получить то, что хочу, но это хороший способ?