2011-04-04 55 views
0

我有一個應用程序,它具有從我的主視圖通過一些定製的UIButtons導航到的許多視圖。主視圖命名爲iBMRViewController,並以通過界面構建​​器放入的PNG圖像形式提供了一些歡迎圖形。它還具有6個自定義UIButtons,我通過使用以下代碼創建了它們;使用一個IBAction切換回主視圖控制器

// This is the code which creates, and defines the properties of the 'Warning' button on the main view. 
    UIButton *warningButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; 
    warningButton.frame = CGRectMake(225.0, 270.0, 60.0, 60.0); 
    [warningButton setTitle:@"" forState:UIControlStateNormal]; 
    warningButton.backgroundColor = [UIColor clearColor]; 
    [warningButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal ]; 
    UIImage *warningButtonImageNormal = [UIImage imageNamed:@"Warning.png"]; 
    UIImage *warningStretchableButtonImageNormal = [warningButtonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0]; 
    [warningButton setBackgroundImage:warningStretchableButtonImageNormal forState:UIControlStateNormal]; 
    UIImage *warningButtonImagePressed = [UIImage imageNamed:@"whiteButton.png"]; 
    UIImage *warningStretchableButtonImagePressed = [warningButtonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0]; 
    [warningButton setBackgroundImage:warningStretchableButtonImagePressed forState:UIControlStateHighlighted]; 
    [warningButton addTarget:self action:@selector(warningButtonAction:) forControlEvents:UIControlEventTouchUpInside]; 
    [self.view addSubview:warningButton]; 

現在,這一切工作正常,按鈕功能完美,顯然我也有行動爲他們設置完美的工作。在每一頁上,我都有一個UINavigationBar和一個UINavigationItem,通過界面構建​​器進行設置,並設置爲使用下面的代碼將我帶回到主視圖;

//This is the code which opens up the new view when 'Begin' button is tapped. 
-(IBAction)beginHomeButtonAction:(id)sender { 
    iBMRViewController *controller = [[BeginView alloc] initWithNibName:@"iBMRViewController" bundle:nil]; 
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
    [self presentModalViewController:controller animated:YES]; 
    [controller release]; 

這也適用,但是,當它把我帶回到了「iBMRViewController」它只顯示什麼通過Interface Builder的XIB文件(即歡迎PNG文件)成立。它不顯示我通過代碼添加的按鈕。

任何人都可以告訴我哪裏出了問題嗎?將不勝感激。

感謝

回答

0

事實上,beginHomeButtonAction不「帶你回到主視圖」。它創建一個新的視圖控制器,並提供一個新的視圖。它與控制器類的類似,但不同於該類的實例

要關閉視圖,並且實際上將用戶帶回主視圖,您必須關閉從主視圖呈現的視圖。如何做到這一點取決於你如何呈現,但你可以嘗試popViewControllerAnimateddismissModalViewControllerAnimated。 (谷歌是你的朋友)

+0

謝謝。我會盡力理解你剛纔說的笑話。當我明白他在說什麼時,谷歌確實是我的朋友。但這個術語對我來說都是比較新的,所以有時很難。我想我對你在說什麼有所瞭解,所以我會試一試。謝謝 – 2011-04-05 10:41:05

+0

沒錯。如有疑問,請在您的原始問題中張貼介紹子視圖的代碼。 – mvds 2011-04-05 10:44:06

+0

我設法解決這個問題,而不是在我的IBAction中使用這段代碼 - iBMRViewController * controller = [[BeginView alloc] initWithNibName:@「iBMRViewController」bundle:nil]; - 我將[[BeginView alloc]更改爲[[iBMRViewController alloc]),它就像一個魅力。 – 2011-04-06 14:56:01

相關問題