2010-12-04 104 views
0

我是iPhone應用程序開發的新手。 我想開發一個iPhone應用程序,當應用程序啓動時有兩個按鈕顯示給用戶。 按鈕1用於用戶登錄。 按鈕2用於用戶註冊。不同按鈕的不同視圖iPhone

如何爲每個按鈕添加視圖,如果登錄按鈕被按下,那麼該視圖加載的文本區域和登錄按鈕很少,而如果按下注冊按鈕則註冊視圖加載的文本區域很少,一個確認註冊的按鈕。

有很多tutorilas的多個視圖,但他們只有一個按鈕在一個視圖,按下該按鈕下一個視圖加載一個按鈕來加載下一個視圖等等等等。在我的情況下,我需要在應用程序加載時在一個視圖上有很多按鈕(至少2個),然後根據按下的按鈕加載該視圖。

任何示例代碼或教程鏈接將不勝感激。

在此先感謝。

回答

0

你想在界面生成器的看法,然後扣一個,您將使用類似的代碼

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]; 
2

進行一個方法和註冊按鈕事件到這個方法

[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]; 
    } 
}