Search code examples
iphoneiosuiviewuiactionsheet

UIActionSheet buttons to display view


I am trying to make the buttons in my UIActionSheet perform a view change using the following code.

-(void)displayActionSheet:(id)sender
    {

actionSheet = [[UIActionSheet alloc] 
                              initWithTitle:nil
                              delegate:nil
                              cancelButtonTitle:@"Cancel"
                              destructiveButtonTitle:nil
                              otherButtonTitles:@"Devanagari", @"English", nil];

actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;

[actionSheet showInView:self.view ];

[actionSheet release];

}

How can I modify this code to make the Devanagari, and English buttons link to their own separate views?


Solution

  • for the sake of making this less confusing, you may want to consider naming your actionSheet something other than actionSheet.

    -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        if(actionSheet == actionSheet)
            {
    
    switch (buttonIndex)
                {
                    case 0:
                    {
                DevanagariViewController *controller1 = [[DevanagariViewController alloc] initWithNibName:@"DevanagariViewController" bundle:nil];
    [self presentModalViewController:controller1 animated:NO];
                    NSLog(@"DevanagariViewController");
                    break;
                    }
    
    
                    case 1:
                    {
                                EnglishViewController *controller2 = [[EnglishViewController alloc] initWithNibName:@"EnglishViewController" bundle:nil];
    [self presentModalViewController:controller2 animated:NO];
                    NSLog(@"EnglishViewController");
                    break;
                    }
    
    
                }   
    
    
            }