2013-02-15 54 views
1

我正在開發一個應用程序,我需要一個要求,當我點擊ActionSheet按鈕我想去nextviewcontroller.I嘗試與休耕代碼,但它wouldnot進入下一viewcontroller.how我可以在storybord.can任意一個幫助me.thanks inadvance連接塞格斯...我如何移動到下一個viewController通過單擊動作腳本按鈕iphone中的故事板iphone

#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 

回答

3

如果要打開新的viewController然後用下面一行嘗試希望它可以幫助你:

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

Synergy是我的ne w控制器名稱將其替換爲您的類名稱根據您的要求更改此代碼。

0

試試這個。它適用於我::

if ([buttonTitle isEqualToString:@"Other Button 1"]) { 

    NSString * storyboardName = @"Main"; 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil]; 
    Paypal_ViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"Paypal_ViewController"]; 
    [self presentViewController:vc animated:YES completion:nil]; 

} 
相關問題