如何通过单击iphone中Storyboard中的ActionSheet按钮移动到下一个viewController

时间:2013-02-15 05:13:43

标签: iphone uiactionsheet

我正在开发一个应用程序,因为我需要一个需求就是当我点击ActionSheet按钮时我想去nextviewcontroller.I尝试使用fallowing代码但它不会去下一个viewcontroller.how我可以连接storybord.can中的segues任何人都帮助我。谢谢... ...

#import <UIKit/UIKit.h>
#import "SecondViewController.h"



@interface Tab2ViewController : UIViewController<UIActionSheetDelegate>
{

    UIActionSheet *actionSheet;
    SecondViewController *secondViewController;
}
@end



#import "Tab2ViewController.h"

@interface Tab2ViewController ()

@end

@implementation Tab2ViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib. 


    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(60.0f, 180.0f, 200.0f,70.0f);
    [button setTitle:@"Show Action Sheet" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button.tintColor = [UIColor darkGrayColor];
    [button addTarget:self action:@selector(showActionSheet:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];



}

- (void)showActionSheet:(id)sender
{
     NSString *actionSheetTitle = @"Action Sheet Demo"; //Action Sheet Title
     NSString *destructiveTitle = @"Destructive Button"; //Action Sheet Button Titles
     NSString *other1 = @"Other Button 1";
     NSString *other2 = @"Other Button 2";
     NSString *other3 = @"Other Button 3";
     NSString *cancelTitle = @"Cancel Button";
     UIActionSheet *actionSheet1 = [[UIActionSheet alloc] initWithTitle:actionSheetTitle delegate:self
     cancelButtonTitle:cancelTitle destructiveButtonTitle:destructiveTitle
     otherButtonTitles:other1, other2, other3, nil];
      actionSheet1.actionSheetStyle=UIActionSheetStyleBlackTranslucent;
     [actionSheet1 showInView:self.view];


}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSLog(@"prepareForSegue1");
    if([[segue identifier] isEqualToString:@"third"])
    {
         NSLog(@"prepareForSegue2");
        secondViewController=[segue destinationViewController];       

    }
}

- (void)actionSheet:(UIActionSheet *)actionSheet1 clickedButtonAtIndex:(NSInteger)buttonIndex
{
    //Get the name of the current pressed button
    NSString *buttonTitle = [actionSheet1 buttonTitleAtIndex:buttonIndex];
    if  ([buttonTitle isEqualToString:@"Destructive Button"])
    {
        NSLog(@"Destructive pressed --> Delete Something");
        [self performSegueWithIdentifier:@"third" sender:nil];
    }
    if ([buttonTitle isEqualToString:@"Other Button 1"])
    {
        NSLog(@"Other 1 pressed");
        [self performSegueWithIdentifier:@"third" sender:nil];
    }
    if ([buttonTitle isEqualToString:@"Other Button 2"])
    {
        NSLog(@"Other 2 pressed");
        [self performSegueWithIdentifier:@"third" sender:nil];
    }
    if ([buttonTitle isEqualToString:@"Other Button 3"])
    {
        NSLog(@"Other 3 pressed");
        [self performSegueWithIdentifier:@"third" sender:nil];
    }
    if ([buttonTitle isEqualToString:@"Cancel Button"])
    {
        NSLog(@"Cancel pressed --> Cancel ActionSheet");
        [self performSegueWithIdentifier:@"third" sender:nil];
    }

}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

2 个答案:

答案 0 :(得分:3)

如果您想打开新的Viewcontroller,请尝试使用以下行,希望它可以帮助您:

   UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
   Synergy *objSynergy = (Synergy *)[mainStoryboard instantiateViewControllerWithIdentifier:@"Synergy"];
  [self presentModalViewController:objSynergy animated:YES];

Synergy是我的新控制器名称,您将其替换为您的类名,根据您的要求更改此代码。

答案 1 :(得分:0)

试试这个。它适用于我::

    $(document).ready(function () {
    $('#logoDiv, #pageTitle').click(function () {
        if (!$("#searchMenu").is(':visible')) {
            $('#searchMenu').show('slide', 'left', 300);
        } else {
            $('#searchMenu').hide('slide', 'left', 300);
        }
    });
});
相关问题