2014-09-16 2 views
5

У меня есть лист действий, который я представляю с помощью UIAlertcontroller в ios8 (xcode 6 beta 5). Я использую UIAlertcontroller, потому что UIActionsheet (который устарел в iOS 8) не работал должным образом в ios8, при нажатии любой опции на листе действий вернул меня к родительскому виду. Теперь я столкнулся с одной проблемой в UIAlertcontroller, двойным нажатием вне листа действия popover возвращает меня к предыдущему родительскому представлению. Ниже мой фрагмент кода:Двойной кран из окна действия снаружи, представленный с использованием UIAlertController, приводит к возврату к родительскому виду в ios8 xcode 6 beta 5

UIAlertController *actionSheetIos8; 

actionSheetIos8 = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; 

NSArray *buttonsArray = [self returnMoreArray]; 
int startY = 10; 
for (int i = 0; i < [buttonsArray count]; i++) { 

    UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:[buttonsArray objectAtIndex:i] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
     NSString *newStr = [buttonsArray objectAtIndex:i]; 
     newStr = [[newStr lowercaseString] stringByReplacingOccurrencesOfString:@" " withString:@"_"]; 
    }]; 
    [actionSheetIos8 addAction:defaultAction];   
} 
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { 
}]; 

[actionSheetIos8 setModalPresentationStyle:UIModalPresentationPopover]; 
UIPopoverPresentationController *popPresenter = [actionSheetIos8 
               popoverPresentationController]; 
popPresenter.sourceView = sender; 
popPresenter.sourceRect = [sender frame]; 
dispatch_async(dispatch_get_main_queue(),^{ 
    [self presentViewController:actionSheetIos8 animated:YES completion:nil]; 
}); 
+0

Я просто испытал те же проблемы с использованием контроллера представления popover; двойное нажатие за пределами popover создает этот неожиданный (и нежелательный) побочный эффект. Ищете решения сейчас ... – idStar

ответ

13

Следующее решение работает для меня в моем поповер сценарии контроллера представления; Я подозреваю, что та же ошибка лежит в основе вашей ситуации:

  1. Установите делегат (соответствует UIPopoverPresentationControllerDelegate протоколу) на вашем UIPopoverPresentationController.
  2. Внедрить метод делегата popoverPresentationControllerShouldDismissPopover:.

Например:

/** 
The presence of this delegate callback inhibits the popover presentation controller 
from mistakenly calling 'dismissViewControllerAnimated:completion:' on us twice. 
*/ 
- (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController; 
{ 
    NSLog(@"delegate method called asking permission to dismiss popover"); 
    return YES; 
} 

Вот еще контекст, в котором я устанавливаю мой контроллер поповер презентации с представленной контроллером и делегатом:

// Set modal presentation style and issue the presentViewController:animated:completion: 
// call before retrieving popover presentation controller created for us, as suggested 
// in the API documentation that is more recent than the sample code from the 
// WWDC2014 slides in Session 228: 
presentedController.modalPresentationStyle = UIModalPresentationPopover; 
[self presentViewController:presentedController animated:YES completion:nil]; 

// Now we can retrieve the popover presentation controller and configure it: 
UIPopoverPresentationController *popPC = presentedController.popoverPresentationController; 
popPC.permittedArrowDirections = UIPopoverArrowDirectionAny; 
CGRect popoverRect = cell.infoButton.bounds; // Assume 'cell' exists; it's an object of mine with an 'infoButton' view. 
popPC.sourceView = cell.infoButton; // has to be provided along with sourceRect 
popPC.sourceRect = popoverRect; // has to be provided along with sourceView 
popPC.delegate = self; // or whomever you set to be your popover presentation controller delegate. 
+0

Это обходное решение работает для меня, используя Xcode 6.0.1 (6A317). – idStar

+0

rdar: // 18481560 подано с Apple и видно на открытом радаре [здесь] (http://openradar.appspot.com/radar?id=6440765035118592). – idStar

+0

FYI - Мой радар был отмечен как обман Apple, поэтому я уверен, что другие сообщают об этом по объему, и правильное исправление поступит в ближайшем будущем. – idStar

 Смежные вопросы

  • Нет связанных вопросов^_^