-2

I have this so far:

        UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        btn.frame = CGRectMake(50, 200, 200, 50);
        [btn setTitle:@"Button 1" forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(someAction) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:btn];

Now I have someAction.. where do I put it and how do I do this? I'm sorry.. I hate asking questions.. but I looked over this everywhere and spent hours..

Lee Duhem
  • 14,695
  • 3
  • 29
  • 47
user3159537
  • 61
  • 1
  • 12
  • possible duplicate of [How to make buttons that go to a different screen?](http://stackoverflow.com/questions/22647811/how-to-make-buttons-that-go-to-a-different-screen) – rmaddy Mar 26 '14 at 02:15
  • Please do not repost your questions. If needed, update your other question with additional details. – rmaddy Mar 26 '14 at 02:15
  • Alright man. Can you help me ? I keep on getting undeclared identifier and I've literally searched everywhere. Look at the comment below. – user3159537 Mar 26 '14 at 02:17
  • If you're getting an error message, you need to post the actual message, not paraphrase. We can't help you if we don't know what the error is. – rdelmar Mar 26 '14 at 02:55

1 Answers1

0

If you're using storyboards, and created a push segue, then the code looks like this

- (void)someAction
{
    [self performSegueWithIdentifier:@"SomeSegueName" sender:nil];
}

If you're using storyboards, but don't have a segue, then the code looks like this

- (void)someAction
{
    MyViewController *vc;

    vc = [self.storyboard instantiateViewControllerWithIdentifier:@"SomeVC"];
    [self.navigationController pushViewController:vc animated:YES];
}

If you aren't using storyboards at all, then I expect your head will eventually start hurting from banging it against the wall.

user3386109
  • 34,287
  • 7
  • 49
  • 68
  • I am using storyboards. Do I put that void on the bottom of the code i wrote in my original post? – user3159537 Mar 26 '14 at 02:09
  • .. because I'm getting "use of undeclared identifier 'someAction' – user3159537 Mar 26 '14 at 02:10
  • Yes, that code goes in the same file as the code you posted. – user3386109 Mar 26 '14 at 02:11
  • What do i do about the undeclared identifier ? – user3159537 Mar 26 '14 at 02:13
  • I don't know why you're getting that. The compiler usually doesn't complain about things that are inside an `@selector`. Are you sure that's the only place `someAction` is used? – user3386109 Mar 26 '14 at 02:23
  • The compiler is complaining about the first line: - (void)someAction { MyViewController *vc; vc = [self.storyboard instantiateViewControllerWithIdentifier:@"SomeVC"]; [self.navigationController pushViewController:vc animated:YES]; } – user3159537 Mar 26 '14 at 07:13
  • Use of undeclared identifier 'someAction' – user3159537 Mar 26 '14 at 15:52
  • I copied and pasted the code from your question into a method called `- (void)test`. No warnings or errors, but it crashes at runtime since the `someAction` method isn't defined. Added the `someAction` method from my post. No warnings or errors. No crash. If you need help finding the source of the error, you need to post your code. – user3386109 Mar 26 '14 at 19:00