Different views for different buttons iPhone
I am a newbie in iPhone app development. I want to develop a iPhone app as when the app is launched there are two buttons displayed for the user. Button 1 is for User Login . Button 2 is for User Registration .
How to add view to each of the button, where if Login button is pressed then that view is loaded with few textfields and a button to login in whereas if Registration button is pressed then the registration view is loaded with few textfields an开发者_如何学JAVAd a button to confirm registration.
There are few tutorilas of multiple views but they have only one button on one view and pressing that button the next view is loaded with one button to load the next view and so on and so forth. In my case I want many buttons (atleast 2 at the moment) on one view while app is loaded and then depending upon the button pressed that view is loaded.
Any sample code or tutorial link will be much appreciated.
Thanks in advance.
make one method and registered button event to this method
[button1 addTarget:self
action:@selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
[button2 addTarget:self
action:@selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
for e.g:
-(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];
}
}
you want to make the views in interface builder, then on button one, you will use code like
ViewControllerSubClass1 *viewController1=[[ViewControllerSubClass1 alloc] initWithNibName:@"nibname1" bundle:nil];
[self.navigationController pushViewController:viewController1];
[viewController1 release];
for button two you would use
ViewControllerSubClass2 *viewController2=[[ViewControllerSubClass2 alloc] initWithNibName:@"nibname2" bundle:nil];
[self.navigationController pushViewController:viewController2];
[viewController2 release];
精彩评论