我正在编写代码,其中从Action Sheet调用另一个视图控制器。我正在使用“performSegueWithIdentifier”,因为我想根据按下的操作按钮传递不同的文本。它运行正常,但现在当我从Action表调用视图控制器时,它会出现然后突然隐藏。我检查了我的代码,但无法找出错误。这是我的代码。注意:我没有使用导航控制器。
//"selectEditor" is the button action used for calling action sheet.
- (IBAction)selectEditor:(id)sender {
_sheet = [[UIActionSheet alloc] initWithTitle:@"Select type of Editor"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Button1",@"Button2", nil];
[_sheet showInView:self.view];
}
//Perform segue to vc when action button is pressed. "editorSegue" is segue identifier.
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
//trigger call here
if (buttonIndex==0)
{
EditorFlag=1;
[self performSegueWithIdentifier:@"editorSegue" sender:self];
}
if (buttonIndex==1)
{
EditorFlag=0;
[self performSegueWithIdentifier:@"editorSegue" sender:self];
}
}
#pragma mark - Navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"editorSegue"]) {
//Additional code here. EditorFlag is used for identification to set different text on same view controller when different action buttons are pressed.
if (EditorFlag==1)
{
//EditTextController is the view controller which hides after showing
EditTextController *textEditor = [segue destinationViewController];
textEditor.textstring=@"some text";
}
else
{
EditTextController *textEditor = [segue destinationViewController];
textEditor.textstring=@"some text";
}
}
}
//Here is Editor text code, I am adding navigation bar manually but I also checked it by commenting all code in it.
@implementation EditTextController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[[self navigationController] setNavigationBarHidden:YES animated:YES];
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width, 50)];
navBar.barTintColor = [UIColor whiteColor];
[self.view addSubview:navBar];
UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStylePlain target:self action:@selector(back:)];
UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:_navString];
[navItem setLeftBarButtonItem:doneItem animated:YES];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"Cloud_Arrow_Up.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(methodAction:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 30, 30)];
navItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
[navBar setItems:[NSArray arrayWithObject:navItem] animated:YES];
[self.textEditor setText:self.textstring];
_textEditor.font = [UIFont fontWithName:@"HelveticaNeue" size:24];
_textEditor.textColor = [UIColor blueColor];
}
-(void)back:(id)sender
{
//[self performSegueWithIdentifier:@"realTimeSegue" sender:sender];
}
- (void)methodAction:(UIButton *)button
{
//[self performSegueWithIdentifier:@"syncSegue" sender:button];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}