0

Здравствуйте, возник вопрос:
На моем ViewController есть выпадающая таблица сверху (TableView - создана программно). Таблица заполнена данными. При нажатии на какое-либо значение из таблицы мне нужно вызвать ActionSheet (я реализовал его в методе didSelectRowAtIndexPath). Проблема в том, что таблица находится как бы за ViewController, и когда происходит событие ActionSheet, то его не видно (на скрине видна суть проблемы). Как мне вызвать ActionSheet на ViewController или может подскажите другой вариант создания ActionSheet?

введите сюда описание изображения

UPDATE 1: Пробовал использовать bringSubviewToFront и sendSubviewToBack, но ничего из это не вышло

UPDATE 2:

Нашел проблему: При создании tableView программно, я использовал следующий код:

     let menuController: UIViewController = UIViewController()
         menuController.view = self
     UIApplication.sharedApplication().delegate?.window??.rootViewController = menuController
     UIApplication.sharedApplication().delegate?.window??.addSubview(ViewController.view)

Поэтому все мои Alert попадали на TableView. Для исправление нужно изменить код следующим образом:

     let menuController: UIViewController = UIViewController()
         menuController.view = self
     UIApplication.sharedApplication().delegate?.window??.addSubview(menuController.view)

1 ответ 1

1

с версии iOS 8.3 нужно использовать UIAlertController:

 UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert"
                           message:@"This is an alert."
                           preferredStyle:UIAlertControllerStyleActionSheet];

 UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
 handler:^(UIAlertAction * action) {}];

 [alert addAction:defaultAction];

показывайте на самом переднем controller-e

 [controller presentViewController:alert animated:YES completion:nil];

если ваш search контроллер не в вашем ViewController классe, используйте delegation,чтобы передать событие из метода didSelectRowAtIndexPath в ваш класс ViewController и там вызвать метод

       [self presentViewController:alert animated:YES completion:nil];

SWIFT

 let alertController = UIAlertController(title: "My Alert", message: "My Alert", preferredStyle: .ActionSheet)

 let defaultAcation = UIAlertAction(title: "OK", style: .Default) { (action) in
     // ...
 }

 alertController.addAction(defaultAcation)

  controller.presentViewController(alertController, animated: true) {
      // ...
 }

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.