UIActionSheet positioning problem

Posted by Dave on Stack Overflow See other posts from Stack Overflow or by Dave
Published on 2010-03-20T17:57:08Z Indexed on 2010/03/20 18:01 UTC
Read the original article Hit count: 745

I need to display a pop with a UISwitch and a Done button when user taps on a button and save the state of the switch when the done button in the pop up is tapped.

So I use UIActionSheet to do this -

sheet = [[UIActionSheet alloc] initWithTitle:@"Switch Setting" 
                                              delegate:self
                                     cancelButtonTitle:nil
                                destructiveButtonTitle:nil
                                     otherButtonTitles:@"Done", nil];

theSwitch = [[UISwitch alloc] init];
[sheet addSubview:theSwitch];
[sheet showInView:self.view];


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == actionSheet.firstOtherButtonIndex)
    {
      theSwitch .on? NSLog(@"Switch is on") : NSLog(@"Switch if off");
    }
}

All this works great. I have problem with positioning. Unfortunately, I don't have a screen shot at the moment to post here. But the switch appears at the very top on the same line with the Action Sheet title and then below that is the Done button. Please someone help me how to position the switch below the Title and increase the Action Sheet size so it looks neat. I need this asap. Thanks.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about ipad