Reputation: 677
I have a button within my view controller which i need to, once clicked, send the user to the next view controller, but it isn't working. I have ctrl dragged from my button to the controller that i want and the connection is made as a UIButton with touchUpInside selected. I have also named the segue but still nothing. The button itself isn't even recognising a touch has been made and isn't sending me anywhere. here is some code below from my main view controller:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
JDTHMainMenu *theMenu = [[JDTHMainMenu alloc] initWithFrame:self.view.bounds];
[self.view addSubview:theMenu];
}
- (IBAction)matchViewControllerButton:(UIButton *)sender
{
UIButton *matchScreenButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[matchScreenButton addTarget:self action:@selector(goToMatchView:sender:) forControlEvents:UIControlEventTouchDown];
[matchScreenButton setUserInteractionEnabled:YES];
NSLog(@"Open Match View");
}
- (void)goToMatchView:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"pushToMatchView"]) {
JDTHMatchScreen *vc2 = (JDTHMatchScreen *)segue.destinationViewController;
vc2.name = self.textField.text;
}
}
I have embedded this view controller in a navcontroller and that is the root controller. I read somewhere that maybe i needed to add something to my appdelegate but nothing was clear. I will post any more code deemed important, again i'm still at the early stages of learning so i'm not sure of which things are relevant.
Upvotes: 0
Views: 1032
Reputation: 1278
Your are not pushing/presenting a view controller, you are only assigning a value to v2.name.
You must fire the segue to push/present the second view controller from your button:
- (void)goToMatchViewController
{
[self performSegueWithIdentifier:@"YOUR_SEGUE_IDENTIFIER" sender:self];
}
This code could be use in prepareForSegue:
to assign var' values to the 2nd VC. check the doc to see more.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"pushToMatchView"]) {
JDTHMatchScreen *vc2 = (JDTHMatchScreen *)segue.destinationViewController;
vc2.name = self.textField.text;
}
}
Upvotes: 5