I’m currently implementing a UIActionsheet that has two buttons.
Each of the buttons save different values into [NSUserDefaults standardUserDefaults]
The implementation i have atm:
-(void)foo{
UIActionSheet *mySheet = [[UIActionSheet alloc] initWithBlabla:blabla];
[mySheet showFromTabBar:myTabBar];
[mySheet release];
{
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == x){
[[NSUserDefaults standardUserDefaults] setValue:foo forKey:bar];
{
else{
// bla
{
}
Now, for the issue i’m having at hand.
I would really like the actionsheet to recognize which of the buttons that was clicked most recently and present that in some way.
So for example, the first time the actionsheet shows, both buttons are gray as default, one button gets pressed and the actionsheet goes away.
The second time the actionsheet shows, it shows up just as the first time. And i’ld like the actionsheet to give the user feedback regarding which of the buttons was most recently pushed. (a different coloring or anything really).
If i could acces the buttons generated within the actionsheet this would be a no-problemo.
In pseudo-code i’d probably want kind of solution as below
UIActionSheet *myActionSheet = [[UIActionSheet] alloc] initwithBlabla:blabla];
if([[userDefaults objectForKey:@"foo"]isEqualToString:@"bar"])
{
[myActionSheet setHighLighted:otherButton2];
}
I would like the actionsheet to recognize what the userdefaults for the key foo is and make adjustments to the buttons within the UIActionSheet.
Any tips and/or pointers on how to implement such a thingie will be highly appreciated!
A UIActionSheet has three distinct button display styles: A destructive button ( Red ) for.. well, destructive actions, a cancel button, which is the bottom one and slightly darker than the regular buttons, and the so-called “other buttons”, which are color gray.
Now, if you want to go with a no-hacky-hacky solution, you can use those three colors to create the effect you need, by simply creating a if-condition and instantiating your actionsheet a bit differently every time.
If you are all into hacky-hacky solutions and want some more colors, you might want to consider iterating over all subviews in the actionsheet and modify their style directly. But be warned: your solution might not work in future releases of iOS since there is no guarantee that internal components without a public API won’t change ( That’s why there is no public API for it in most cases ).