UIActionSheet按钮显示视图

时间:2012-03-09 21:20:12

标签: iphone ios uiview uiactionsheet

我正在尝试使用以下代码使我的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];

}

如何修改此代码以使梵文和英文按钮链接到各自的独立视图?

2 个答案:

答案 0 :(得分:2)

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];
    if([title isEqualToString:@"Devanagari"]) {
        //Code if Devanagari button is pressed
    }
    if([title isEqualToString:@"English"]) {
        //Code if English button is pressed
    }
}

答案 1 :(得分:1)

为了减少这种混乱,您可能需要考虑将actionSheet命名为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;
                }


            }   


        }