gpt4 book ai didi

ios - 如何在 UIActionSheet 中为按钮设置 valueForKey?

转载 作者:行者123 更新时间:2023-11-29 01:13:48 24 4
gpt4 key购买 nike

我完全改造了一个旧项目,因为他们使用 UIActionSheet,我不熟悉它所以请帮助我找出答案。

UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"beard Selection" delegate:self cancelButtonTitle:@"Cancel"   destructiveButtonTitle:@""   otherButtonTitles:@"", @"", @"", @"", @"", @"", @"", @"", nil];

NSLog(@"kishore calculation ");
[[[popupQuery valueForKey:@"_buttons"] objectAtIndex:0] setImage:[UIImage imageNamed:@"ca1.png"] forState:UIControlStateNormal];
[[[popupQuery valueForKey:@"_buttons"] objectAtIndex:1] setImage:[UIImage imageNamed:@"ca2.png"] forState:UIControlStateNormal];
[[[popupQuery valueForKey:@"_buttons"] objectAtIndex:2] setImage:[UIImage imageNamed:@"ca3.png"] forState:UIControlStateNormal];
[[[popupQuery valueForKey:@"_buttons"] objectAtIndex:3] setImage:[UIImage imageNamed:@"ca4.png"] forState:UIControlStateNormal];
[[[popupQuery valueForKey:@"_buttons"] objectAtIndex:4] setImage:[UIImage imageNamed:@"ca5.png"] forState:UIControlStateNormal];
[[[popupQuery valueForKey:@"_buttons"] objectAtIndex:5] setImage:[UIImage imageNamed:@"ca6.png"] forState:UIControlStateNormal];
[[[popupQuery valueForKey:@"_buttons"] objectAtIndex:6] setImage:[UIImage imageNamed:@"ca7.png"] forState:UIControlStateNormal];
[[[popupQuery valueForKey:@"_buttons"] objectAtIndex:7] setImage:[UIImage imageNamed:@"ca8.png"] forState:UIControlStateNormal];
[[[popupQuery valueForKey:@"_buttons"] objectAtIndex:8] setImage:[UIImage imageNamed:@"ca9.png"] forState:UIControlStateNormal];
[[[popupQuery valueForKey:@"_buttons"] objectAtIndex:9] setImage:[UIImage imageNamed:@"ca10.png"] forState:UIControlStateNormal];

popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery setTag:Cap];
[popupQuery showInView:self.view];

UIActionSheet 就像一个 UIAlertView ,因为他们试图添加按钮,但我收到这样的错误,

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ valueForUndefinedKey:]: this class is not key value coding-compliant for the key buttons.'

指导我克服这个:)

最佳答案

_buttons 没有出现在公共(public) Api 中。如果你使用这个,苹果不同意你的应用程序。所以根据新概念实现你的代码,就像这样

UIAlertController * view=   [UIAlertController
alertControllerWithTitle:@"XXX "
message:@"pickAnyone"
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* first = [UIAlertAction
actionWithTitle:@"abc"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
//Do some thing here
[view dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction* second = [UIAlertAction
actionWithTitle:@"cde+"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[view dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction* third = [UIAlertAction
actionWithTitle:@"hhh"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction * action)
{
[view dismissViewControllerAnimated:YES completion:nil];

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

[first setValue:[[UIImage imageNamed:@"abc.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"];
[second setValue:[[UIImage imageNamed:@"cde+.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"];
[third setValue:[[UIImage imageNamed:@"hhh"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"];

[view addAction:first];
[view addAction:second];
[view addAction:third];
[view addAction:cancel];

[self presentViewController:view animated:YES completion:nil];
}

关于ios - 如何在 UIActionSheet 中为按钮设置 valueForKey?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35458734/

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