2012-02-22 211 views
2

我現在正在開發支持iOS 4.3和5.0的應用程序。導航欄問題iphone 4.3

我的代碼可以正常工作5.0,但會導致4.3中的棘手問題。

問題是:

我有一個視圖,其中有一個tableView。該視圖具有導航欄,其中包含左側和右側導航欄項目。一旦我選擇表格視圖中的行(併到達相應的視圖)並返回,左側和右側的導航欄項目「消失」。

過去幾個小時我一直在這個爛攤子上,有人得到了治療?

這是我已經做了:

這是實用的方法,我稱之爲視負載時。

+ (void)setNavigationBarContents:(UIViewController *)view 
{ 


UIImage *topBarimage=[UIImage imageNamed:NAVIGATION_BAR_IMAGE]; 


if([view.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) { 

    [view.navigationController.navigationBar setBackgroundImage:topBarimage forBarMetrics:UIBarMetricsDefault]; 
} 
else 
{ 
    [view.navigationController.navigationBar insertSubview:[[UIImageView alloc] initWithImage:topBarimage] aboveSubview:view.navigationController.navigationBar]; 

} 

UIImage *logo=[UIImage imageNamed:LOGO]; 
UIImageView *logoView=[[UIImageView alloc]initWithImage:logo]; 
view.navigationItem.titleView = logoView; 

UIImage *settingsButtonImage= [UIImage imageNamed:NAVIGATION_SETTINGS]; 
UIButton *rightBarButton = [UIButton buttonWithType: UIButtonTypeCustom]; 
[rightBarButton setBackgroundImage: settingsButtonImage forState:UIControlStateNormal]; 
[rightBarButton addTarget: view action:@selector(settingsButton:) forControlEvents:UIControlEventTouchUpInside]; 
rightBarButton.frame = CGRectMake(0, 0, 50, 40); 
view.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: rightBarButton]; 

UIImage *logoutButtonImage= [UIImage imageNamed:LOGOUT]; 
UIButton *leftBarButton = [UIButton buttonWithType: UIButtonTypeCustom]; 
[leftBarButton setBackgroundImage: logoutButtonImage forState:UIControlStateNormal]; 
[leftBarButton addTarget: view action:@selector(logout:) forControlEvents:UIControlEventTouchUpInside]; 
leftBarButton.frame = CGRectMake(0, 0, 65, 32); 
view.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: leftBarButton]; 


} 

已經嘗試在viewDidLoad和viewWillAppear中調用這個,但徒勞無功。

這就是我在viewController中調用它的方法。

- (void)viewDidLoad 
{ 

[super viewDidLoad]; 

//other setups here. 

[Utility setNavigationBarContents:self]; 

} 
+0

嘗試在viewWillAppear中這段代碼[實用setNavigationBarContents:自我]。 – Splendid 2012-02-22 07:10:33

+0

我已經嘗試過了,正如我之前所說的。感謝您的快速回復 – Guru 2012-02-22 07:14:47

+0

只有酒吧按鈕項消失或導航欄消失? – Splendid 2012-02-22 10:55:41

回答

3

我得到了解決由我appDelegate.m添加 此代碼

// added so that navigation bar background image works in version lower than 5.0 

@implementation UINavigationBar (UINavigationBarCategory) 
- (void)drawRect:(CGRect)rect { 
UIImage *img = [UIImage imageNamed:NAVIGATION_BAR_IMAGE]; 
[img drawInRect:rect]; 
} 
@end