不同按钮的不同视图iPhone
问题描述:
我是iPhone应用程序开发的新手。 我想开发一个iPhone应用程序,当应用程序启动时有两个按钮显示给用户。 按钮1用于用户登录。 按钮2用于用户注册。不同按钮的不同视图iPhone
如何为每个按钮添加视图,如果登录按钮被按下,那么该视图加载的文本区域和登录按钮很少,而如果按下注册按钮则注册视图加载的文本区域很少,一个确认注册的按钮。
有很多tutorilas的多个视图,但他们只有一个按钮在一个视图,按下该按钮下一个视图加载一个按钮来加载下一个视图等等等等。在我的情况下,我需要在应用程序加载时在一个视图上有很多按钮(至少2个),然后根据按下的按钮加载该视图。
任何示例代码或教程链接将不胜感激。
在此先感谢。
答
你想在界面生成器的看法,然后扣一个,您将使用类似的代码
ViewControllerSubClass1 *viewController1=[[ViewControllerSubClass1 alloc] initWithNibName:@"nibname1" bundle:nil];
[self.navigationController pushViewController:viewController1];
[viewController1 release];
了两个按钮,你会用
ViewControllerSubClass2 *viewController2=[[ViewControllerSubClass2 alloc] initWithNibName:@"nibname2" bundle:nil];
[self.navigationController pushViewController:viewController2];
[viewController2 release];
答
进行一个方法和注册按钮事件到这个方法
[button1 addTarget:self
action:@selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
[button2 addTarget:self
action:@selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
例如:
-(IBAction)buttonClicked : (id)sender
{
UIButton * btn = (UIButton *)sender;
if (btn == button1) {
LoginViewController * controller = [[LoginViewController alloc] initWithNibName:@ "LoginViewController" bundle:nil];
[self.navigationController pushViewController : controller animated : YES];
[controller release];
} else if (btn == button2) {
RegisterViewController * controller = [[RegisterViewController alloc] initWithNibName:@ "RegisterViewController" bundle:nil];
[self.navigationController pushViewController : controller animated : YES];
[controller release];
}
}