UIActionSheet按钮未加载新视图

时间:2012-03-09 22:18:25

标签: iphone ios cocoa-touch uiactionsheet

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

当我按下梵文按钮时,它应该加载一个新视图,但它只是在不加载新视图的情况下解除UIActionSheet
我在这里做错了吗?

2 个答案:

答案 0 :(得分:4)

actionSheet.delegate = self;中需要displayActionSheet method,否则将无法调用UIActionSheetDelegate方法。

或者在init方法中提供委托。您目前正将其设置为nil

我刚刚确认以下工作:

- (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__);
}

答案 1 :(得分:1)

确保您已在界面中添加了委托

@interface mainviewcontroller : UIViewController <UIActionSheetDelegate> {

}

(编辑)然后将委托更改为自我

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