0

I have a main view (contains a table view of profiles) which has a Navigation Controller. In the navigation bar I have a "menu" bar button. When the user clicks the bar button, a Menu View is added as a subview to the main view. This Menu View (which is a subview) has a button. This button is going to be used to segue to another view in my story board (not a sub view).

This code in my Menu View's .m file doesn't work:

- (IBAction)button:(UIButton *)sender {
    [AlertStatus alertStatus:@"" :@"Message1" :0];
    [sender performSegueWithIdentifier:@"segueTo1" sender:sender];
}

I get a "No visible @interface for 'UIButton' declares the selector performSegueWithIdentifier:sender:'" error message

Can anyone help? I also heard of using a delegate to the main view but I have no experience in that.

lr100
  • 648
  • 1
  • 9
  • 29

2 Answers2

2

This is very easy to fix. You have to perform the segue from the view controller, not the button.

- (IBAction)button:(UIButton *)sender {
    [AlertStatus alertStatus:@"" :@"Message1" :0];
    [self performSegueWithIdentifier:@"segueTo1" sender:sender];
}

This code will work

Argent
  • 390
  • 1
  • 3
  • 11
  • I tried what I think you are saying. But it still doesn't work. Does this code go in the NIB .m file or the ViewController .m file? I am going the edit the top portion to explain alittle better. – lr100 May 19 '14 at 02:32
  • You have to put this in the ViewControllers .m file. You should make your ViewController the delegate of your button and than perform the segue from the ViewController with `[self performSegueWithIdentifier:@"segueTo1" sender:sender];` Just remember: only a view controller can perform a segue, not a view – Argent May 19 '14 at 04:47
  • Thanks for the information. I will research delegates for button clicks. If you want to, an example would be awesome and helpful to myself and others :) – lr100 May 20 '14 at 20:37
0

i don't know using segue but you can also do with below code. if it is not necessary to do with segue than you can use this code.

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
OtherViewController *mvc = [sb instantiateViewControllerWithIdentifier:@"OtherViewController"];        
[self.navigationController pushViewController:mvc animated:YES];
Nisha
  • 354
  • 2
  • 19