Reputation: 4375
I am totally revamp one of the old project ,and in that they using UIActionSheet
,i am not familiar with it so please help me to find out .
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
is like a UIAlertView
,in that they tried to add buttons but i am getting error like this ,
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ valueForUndefinedKey:]: this class is not key value coding-compliant for the key buttons.'
guide me to over come this :)
Upvotes: 0
Views: 689
Reputation: 82759
_buttons
does not comes in public Api. if you use this the apple does not agree your app. so Implemnt your code based on new concept, like this
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];
}
Upvotes: 1
Reputation: 131426
This code is using KVO to try to access private properties of the UIActionSheet class. This is a bad idea, and may get your app rejected from the app store.
It's a bad idea because it relies on private implementation details of Apple's frameworks. In this case, it probably stopped working because Apple changed those private implementation details.
Upvotes: 0