2011-11-04 85 views
0

我一直在研究ipad應用程序。在這個應用程序中,我有幾個觀點。這裏是流動如何從導航欄中刪除按鈕?

歡迎屏幕>主屏幕>休息

我已經申請的所有屏幕的導航欄上的主頁圖標(按鈕)sreens的。在任何屏幕上按主屏幕圖標都會使用戶進入主屏幕。我在Home類的viewDidLoad中編寫了以下代碼

//**** Home button on navigation bar ****// 
CGRect frame1 = CGRectMake(975.0, 4.0, 35, 35); 
UIImage *buttonImage1 = [UIImage imageNamed:@"HomeIcon.png"]; 
UIButton *homeButton = [UIButton buttonWithType:UIButtonTypeCustom]; 

homeButton.frame = frame1; 
[homeButton setBackgroundImage:buttonImage1 forState:UIControlStateNormal]; 
homeButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
homeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; 
[homeButton addTarget:self action:@selector(goHome:) forControlEvents:UIControlEventTouchUpInside]; 
[homeButton setBackgroundColor:[UIColor clearColor]]; 

[self.navigationController.navigationBar addSubview:homeButton]; 

此按鈕功能正常。 goHome是在@selector中應用的方法的名稱。 我想從主屏幕中刪除此按鈕並將其保留在屏幕的其餘部分。我已經應用了幾件事,但我不知道如何去做。這似乎很簡單,但我仍然沒有得到它。請指導..

問候 PC

回答

3

在你的 「主屏幕」 viewDidAppear方法做到這一點:

for(UIView* view in self.navigationController.navigationBar.subviews) 
{ 
    if(view.tag == 10) 
    { 
     view.hidden = YES; 
    } 
} 

在你的其他瀏覽器,你創建主頁按鈕的按鈕組標籤爲10.

/**** Home button on navigation bar ****// 
CGRect frame1 = CGRectMake(975.0, 4.0, 35, 35); 
UIImage *buttonImage1 = [UIImage imageNamed:@"HomeIcon.png"]; 
UIButton *homeButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[homebutton setTag:10]; // Set tag to 10 or any value 
homeButton.frame = frame1; 
[homeButton setBackgroundImage:buttonImage1 forState:UIControlStateNormal]; 
homeButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
homeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; 
[homeButton addTarget:self action:@selector(goHome:) forControlEvents:UIControlEventTouchUpInside]; 
[homeButton setBackgroundColor:[UIColor clearColor]]; 

[self.navigationController.navigationBar addSubview:homeButton]; 

而且在你viewDidAppear:這個其他視圖控制器:

for(UIView* view in self.navigationController.navigationBar.subviews) 
{ 
    if(view.tag == 10) 
    { 
     view.hidden = NO; 
    } 
} 
+0

感謝朋友..它的工作.. –

1

試試這個:

self.navigationItem.backBarButtonItem = nil;