user1120133
user1120133

Reputation: 3234

UIActionSheet button not loading new view

-(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];

}

-(void)ActionSheet:(UIActionSheet *)ActionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

if(actionSheet == actionSheet)
{
switch (buttonIndex) {

    case 0:{

        //Devanagari view display 

        ButtonViewController *controller1 = [[ButtonViewController alloc]init];

        controller1.delegate = self;

        UINavigationController *navigationController = [[UINavigationController alloc]
                                                        initWithRootViewController:controller1];
        navigationController.navigationBar.tintColor = [UIColor colorWithHue:2.0/12 saturation:2.0 brightness:4.0/10 alpha:1.0];

        [self presentModalViewController:navigationController animated:YES];

        [navigationController release];

        break;
    }        
}
 }
   }

When I press the Devanagari button it should load a new view, but it is simply dismissing UIActionSheet without loading the new view.
Am I doing something wrong over here?

Upvotes: 0

Views: 734

Answers (2)

AppyMike
AppyMike

Reputation: 2064

Make sure you have added the delegate in your interface

@interface mainviewcontroller : UIViewController <UIActionSheetDelegate> {

}

(EDIT) And then change the delegate to self

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

Upvotes: 1

FluffulousChimp
FluffulousChimp

Reputation: 9185

You need actionSheet.delegate = self; in your displayActionSheet method Otherwise the UIActionSheetDelegate methods won't be called.

Or provide a delegate in your init method. You are currently setting it to nil.

I just confirmed that the following works:

- (void)displayActionSheet;
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self 
                                                    cancelButtonTitle:@"Cancel" 
                                               destructiveButtonTitle:nil 
                                                         otherButtonTitles:@"Devanagari",@"English", nil];
    [actionSheet showInView:self.view];
    [actionSheet release];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
{
    NSLog(@"%s - Called!",__FUNCTION__);
}

Upvotes: 4

Related Questions