我正在开发一个应用程序,因为我需要一个要求,即当我单击 ActionSheet 按钮时,我想转到下一个视图控制器。我尝试使用休闲代码,但它不会转到下一个视图控制器。我如何在 storybord 中连接 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