gpt4 book ai didi

iOS 7 -(无效)setupAlertCtr :(NSString*)choseMenuType compatibility

转载 作者:行者123 更新时间:2023-11-29 10:34:44 27 4
gpt4 key购买 nike

-(void)setupAlertCtr:(NSString*)choseMenuType
{
self.alertContForNew = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"İptal" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action)
{

}];

[self.alertContForNew addAction:cancel];
}

此代码适用于 iOS 8,但当我尝试在 iOS 7 上使用时出现崩溃问题是什么?

最佳答案

因为 UIAlertController只支持iOS 8及以后的版本,在iOS 7中我们还是要用UIActionSheetUIAlertView

所以你必须像下面这样放置条件

if (ios8)// change your condition which check ios8 or later.
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];

UIAlertAction* alertAction1 = [UIAlertAction actionWithTitle:@"Your title" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
//do what you want
}];

[alert addAction:cancelAction];
[alert addAction:alertAction1];

[self presentViewController:alert animated:YES completion:nil];
}
else
{
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"Title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Your Title",nil];
[actionSheet showInView:self.view];
}

对于 iOS 7 你必须实现 <UIActionSheetDelegate>及其方法

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0:
//do what you want.
break;
case 1:
break;
default:
break;
}
}

关于iOS 7 -(无效)setupAlertCtr :(NSString*)choseMenuType compatibility,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27704507/

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