tags:

views:

105

answers:

1

I have a button that I'm creating in a UIViewController like so:

TOLoginButton* button = [[[TOLoginButton alloc] initWithFrame:CGRectMake(60,180,200,40)] autorelease];

[self.view addSubview:button];

The button is a UIControll and I'm trying to call another UIViewController from within the touchUpInside method, below is what I have but it doesn't work:

  • (void)touchUpInside {

    MyViewController *viewController = [[MyViewController alloc] init]; [super.view addSubview:viewController.view ]; }

I'm basically trying to call this viewController once my button is pressed.

So viewController1 has the button on it and once the button is pressed I want to do something like [viewController1.view addSubview:viewController2.view].

Any help will be appreciated

+1  A: 

assuming the new UIViewController is full-screen, the more usual thing to do is

[self presentModalViewController:viewController animated:YES];

or if you're using a navigation controller

[self.navigationController pushViewController:viewController animated:YES];
David Maymudes
The problem is that self is a UIControl so are yo saying you can call presentModalViewController on a UIControll, cause it gives errors if you do?
TheGambler
ah, sorry, that code was meant to live in a UIViewController subclass. I've only used interface builder to add UIControls, so I'm not entirely sure, but I think what you need to do is call [button addTarget:self action:@selector("buttonWasPressed") forControlEvents:UIControlEventTouchUpInside] which will tell the button to run the "buttonWasPressed" method in your view controller, and then you can load the other view controller from there.
David Maymudes