从UIControl的touchUpInside方法中调用UIViewController

时间:2009-09-13 22:10:18

标签: iphone

我有一个按钮,我正在UIViewController创建,如此:

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

[self.view addSubview:button];

该按钮是UIControl,我正试图从UIViewController方法中调用另一个touchUpInside,下面是我所拥有的但不起作用:

- (void)touchUpInside {

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

按下按钮后,我基本上会尝试调用此viewController

因此viewController1上有按钮,按下按钮后我想做[viewController1.view addSubview:viewController2.view]之类的事情。

1 个答案:

答案 0 :(得分:1)

假设新的UIViewController是全屏的,更常见的事情是

[self presentModalViewController:viewController animated:YES];

或者如果您使用的是导航控制器

[self.navigationController pushViewController:viewController animated:YES];