gpt4 book ai didi

ios - 未捕获的异常 'NSGenericException : application has presented a UIAlertController of style UIAlertControllerStyleActionSheet

转载 作者:行者123 更新时间:2023-12-01 15:57:46 24 4
gpt4 key购买 nike

我正在开发一个在 iPhone 上运行的应用程序运行良好,但是当我尝试在 iPad 上运行时它崩溃了

这是我的代码:

- (void)parseCountryStates:(NSDictionary *)json
{
countryPickerView.hidden = TRUE;
NSDictionary *listing = [json objectForKey:@"country"];
countryArray = [listing allValues];
countryIDArray = [listing allKeys];

[countryPickerView reloadAllComponents];
alertController = [UIAlertController
alertControllerWithTitle:@"Select Service Type"
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
int count = (int)[countryPickerView numberOfRowsInComponent:0];

for (int i = 0; i < count; i++)
{
UIAlertAction* button = [UIAlertAction
actionWithTitle:[[countryPickerView delegate] pickerView:countryPickerView titleForRow:i forComponent:0]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
countryField.text = [action title];
countryStr = countryField.text;
if ([countryArray containsObject:countryStr]) {
countryidStr = [countryIDArray objectAtIndex:[countryArray indexOfObject:countryStr]];
NSLog(@"CountryidStr %@",countryidStr);
[self getState];
}
}];
[alertController addAction:button];

}

UIAlertAction* cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action)
{
// UIAlertController will automatically dismiss the view
}];
[alertController addAction:cancel];
[self presentViewController:alertController animated:true completion:nil];
}

我正在分享它的崩溃日志

*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIAlertController () 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.

最佳答案

将源 View 和源矩形添加到您的 alertController。

[[alertController popoverPresentationController] setSourceView:self.view];
[[alertController popoverPresentationController] setSourceRect:CGRectMake(0,0,1,1)];
[[alertController popoverPresentationController] setPermittedArrowDirections:UIPopoverArrowDirectionUp];

[self presentViewController:alertController animated:true completion:nil];

关于ios - 未捕获的异常 'NSGenericException : application has presented a UIAlertController of style UIAlertControllerStyleActionSheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52438140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com