Need Help with pushing a new view when pushing a button

Discussion in 'iOS Development' started by abotsch31, Jun 21, 2009.

  1. abotsch31

    abotsch31 Banned

    Joined:
    Feb 9, 2009
    Messages:
    31
    Likes Received:
    0
    Hey, it would be great if someone could help me with a little problem I am having...

    I have a view with 5 round rect buttons and I am wanting to push a new view when each of them is pushed. I am wanting each button to go to a different view, not the same, but hopefully using the same IBAction.

    In my .h I have each button with an IBOutlet and then I declare the
    - (IBAction)buttonPressed

    Please Register or Log in to view images

    id)sender;

    Then, in my .m I am wanting to have that action push a new view.
    - (IBAction)buttonPressed

    Please Register or Log in to view images

    id)sender {
    what do i put here to push a new view
    }

    Any help would be awesome, thanks.
    Abotsch31
  2. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    If you are using view controllers use either
    Code:
    [self pushModalViewController:someOtherViewController];
    OR

    Code:
    [self.view addSubview: someOtherView];
    OR

    Code:
    [self.view addSubview: someOtherViewController.view];
    or if working directly from UIView's

    Code:
    [someView addSubview: someOtherView];
  3. abotsch31

    abotsch31 Banned

    Joined:
    Feb 9, 2009
    Messages:
    31
    Likes Received:
    0
    hey thanks for replying so quick, so I only need to put on of these lines of code and I am good.
  4. Just_For_Now

    Just_For_Now Active Member

    Joined:
    Mar 21, 2009
    Messages:
    1,898
    Likes Received:
    1
    Device:
    4G iPod touch
    no, -.-
    Replace the "SomeOtherViewController" with the viewcontroller you want it to switch to.
  5. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    Depends whether you're using UIViewController's or not.
  6. abotsch31

    abotsch31 Banned

    Joined:
    Feb 9, 2009
    Messages:
    31
    Likes Received:
    0
    ok, so I added [self pushModalViewController:someViewController];
    and changing someViewController to my viewcontroller I want the button to go to, but I got an error of

    error: syntax error before 'redButtonViewController'

    but I don't know what it is, this is what I put in...

    - (IBAction)buttonPressed

    Please Register or Log in to view images

    id)sender
    {
    [self pushModalViewController:redButtonViewController];
    }
  7. Just_For_Now

    Just_For_Now Active Member

    Joined:
    Mar 21, 2009
    Messages:
    1,898
    Likes Received:
    1
    Device:
    4G iPod touch
    Is it a view ur trying to add to the view or a viewController?
  8. abotsch31

    abotsch31 Banned

    Joined:
    Feb 9, 2009
    Messages:
    31
    Likes Received:
    0
    I added a .h and .m UIViewController Subclass to classes and I also created a .xib file with a viewcontroller, no view, that has only a red background.
  9. Just_For_Now

    Just_For_Now Active Member

    Joined:
    Mar 21, 2009
    Messages:
    1,898
    Likes Received:
    1
    Device:
    4G iPod touch
    well. First you need the project to recognize the viewController.
    Try putting this in:
    Code:
    -(IBAction)buttonPressed:(id)sender{
    redButtonViewController *redView;
    redView = [[redButtonViewController alloc] initWithNibName:@"redButtonViewController" bundle:nil];
    [self pushModalViewController:redView];
    }
    Make sure you also #import the redButtonViewController into the .m
  10. abotsch31

    abotsch31 Banned

    Joined:
    Feb 9, 2009
    Messages:
    31
    Likes Received:
    0
    ya, thanks, that helped a lot, I have no errors now but I still have 1 warning saying "YourNumberViewController", which is the view with all the buttons, may not respond to PushModalViewController.
    ------------------double post merged------------------
    the warning is also saying...

    messages without a matching method signature will be assumed to return 'id and accept '_ _ _' as arguments

    So I am guessing there is something wrong with what I put in my .h file, I'm pretty sure I did everything right though, this is what I put,

    - (IBAction)buttonPressed

    Please Register or Log in to view images

    id)sender;

Share This Page