मैं इस कोड एक UIViewController में बैठे है (XCode 6.1, आईओएस 8.1.1) का उपयोग रन-टाइम त्रुटि को ठीक:कैसे UIAlertController
[UIAlertController showActionSheetInViewController:self
withTitle:@"Test Action Sheet"
message:NSLocalizedString(@"Are you sure you want to delete ALL appointments?",nil)
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Yes"
otherButtonTitles:@[@"No"] // same as Cancel
tapBlock:^(UIAlertController *controller, UIAlertAction *action, NSInteger buttonIndex){
if (buttonIndex == UIAlertControllerBlocksCancelButtonIndex) {
NSLog(@"Cancel Tapped");
} else if (buttonIndex == UIAlertControllerBlocksDestructiveButtonIndex) {
NSLog(@"Delete Tapped");
} else if (buttonIndex >= UIAlertControllerBlocksFirstOtherButtonIndex) {
NSLog(@"Other Action Index %ld", (long)buttonIndex - UIAlertControllerBlocksFirstOtherButtonIndex);
}
}];
जब मैंने इसे चलाने के लिए, मैं इस रन-टाइम त्रुटि मिलती है:
*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIAlertController (<UIAlertController: 0x7fdfe3324f00>) of style UIAlertControllerStyleActionSheet. The modalPresentationStyle of a UIAlertController with this style is UIModalPresentationPopover. You must provide location information for this popover through the alert controller's popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.'
इस काम को करने के लिए मुझे क्या करने की ज़रूरत है? (मैंने एसओ और Google को देखा है और कुछ भी विशिष्ट नहीं पाया है)। मैं इस पर प्राप्त किसी भी मदद की सराहना करता हूं ...
अद्यतन मैंने इसे तृतीय-पक्ष कोड के बिना फिर से लिखा; इस कोड को जोड़ा, और अब यह काम करता है!
UIAlertController * view= [UIAlertController
alertControllerWithTitle:@"My Title"
message:@"Select your Choice"
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
//Do some thing here
[view dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[view dismissViewControllerAnimated:YES completion:nil];
}];
[view addAction:ok];
[view addAction:cancel];
view.popoverPresentationController.sourceView = self.view;
view.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width/2.0, self.view.bounds.size.height/2.0, 1.0, 1.0);
[self presentViewController: view animated:YES completion:nil];
मैंने सही कोड के साथ प्रश्न अद्यतन किया। आपकी मदद के लिए धन्यवाद, ब्रैड! मैं इसकी सराहना करता हूं। – SpokaneDude