2011-05-09 105 views
1

嘿傢伙我是一個可可的新手開發人員,我試圖創建一個簡單的應用程序。其中顯示4個不同的頁面,您可以通過標籤欄進行選擇。(Xcode)UIButtons和頁面之間的鏈接

我的問題:我在IB的First/Home頁面(==> FirstView.xib)上做了一個UIButton,我嘗試將它鏈接到我的第二頁(==> SecondView.xib)互聯網。

事情是,我可以建立我的代碼,但沒有反應,當我嘗試點擊我的按鈕,你能幫我嗎?

代碼FirstView.h:

#import <UIKit/UIKit.h> 


@interface FirstViewController : UIViewController { 

UIButton *button;} 

@property (nonatomic, retain) IBOutlet UIButton *button; 

- (IBAction)goToViewTwo; 

@end 

代碼FirstView.m: @implementation FirstViewController @synthesize按鈕;

- (IBAction)goToViewTwo { 
SecondViewController *SecondView= [[SecondViewController alloc] initWithNibName: @"SecondView" bundle:[NSBundle mainBundle]]; 
[self.navigationController pushViewController:SecondView animated:YES]; 
} 

- (void)didReceiveMemoryWarning { 
// Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

- (void)dealloc { 
    [super dealloc]; 
    [button release]; 
} 

@end 

關於在FIrstVIew.xib網點:

我聯繫 「潤色內」 向 「goToViewTwo」 和 「b^utton」 到「文件擁有者」

回答

0

我在印象中這是在一個標籤欄中,每個標籤欄按鈕顯示一個.xib文件,如果是這種情況,解決方案非常簡單,你的tabBarController管理視圖控制器數組中的視圖。 IBAction方法應該如下:

- (IBAction)goToViewTwo { 
    self.tabBarController.selectedIndex = 1; 
} 

這告訴你的標籤欄控制器從當前視圖控制器切換(位於索引0)到第二(在索引1)

+0

聖小號*** ^^,非常感謝你(覺得如此愚蠢現在:o)它工作正常:) – Nicolas 2011-05-09 20:17:25

+0

我的榮幸,男人。雖然沒有必要感到愚蠢。隨着時間的推移,你會發現一些有用的東西。一個被接受的答案將不勝感激,雖然=] – justin 2011-05-09 20:33:20