UIActionSheet按钮加载新视图

时间:2009-07-17 02:34:18

标签: iphone

我今晚一直在尝试这个...我在自己的控制器中有一个UIActionSheet。我在视图中导入控制器我希望它显示。当用户按下其中一个按钮时,我无法弄清楚如何显示新视图(您可以看到我刚刚发送警报的位置)。有什么想法吗?

- (void)helpButtonPressedView {
    // open a dialog with two custom buttons
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@""
                                                    delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
                                                    otherButtonTitles:@"Help", @"Credits", nil];
    [self parentViewController];
    actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
    [actionSheet showInView:self.view]; // show from our table view (pops up in the middle of the table)
    [actionSheet release];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSLog(@"Button Pressed: %d",buttonIndex);

    int btn = buttonIndex;

    UIAlertView *alert;

    switch (btn) {
        case 0:
            // help screen
            alert = [[UIAlertView alloc] initWithTitle:@"Button Press Notice" message:@"The Help screen will be dispayed"
                                                           delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];   
            [alert release];

//          helpViewController = [[HelpViewController alloc] init]; 
//          [self presentModalViewController:helpViewController animated:YES];

            break;
        case 1:
            // credits screen
            alert = [[UIAlertView alloc] initWithTitle:@"Button Press Notice" message:@"The Credits screen will be dispayed"
                                              delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];   
            [alert release];            
            break;
        default:
            break;
    }

}

这是我想要做的图片...当用户按下“帮助”按钮时,会显示一个新视图。当用户按下“Credits”按钮时,会显示另一个视图。我正在使用IB来创建视图。

alt text http://thecoolestcompany.com/UIActionSheet-view.jpg

2 个答案:

答案 0 :(得分:0)

您可以创建视图并将其添加到当前视图,而不是警报:

UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(100,100,100,100)];
[self.view addSubview:newView];
[newView release];

答案 1 :(得分:0)

我提出这个问题已经有一段时间了 - 我刚才想出来......我错过了导航控制器来推动视图控制器。换句话说,创建视图控制器,然后使用导航控制器推送视图。如果有人正在阅读此内容并需要示例代码,请发布问题并发布示例代码......