2009-10-10 46 views
0

這裏是我的代碼....?如何整合UINavigation與酒吧的UIBarButtonItem?如何UINavigation酒吧的UIBarButtonItem集成?

UINavigationBar *nav= [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 60)]; 
nav.backgroundColor = [UIColor whitecolor]; 
//nav.tintColor = [UIColor darkGrayColor]; 
[self.view addSubview:nav]; 
[nav release]; 

回答

0

嘗試初始化您的項目,然後

nav.leftBarButtonItem = barButtonItem; 

nav.rightBarButtonItem = barButtonItem; 

您只能有導航欄上

0

注意的UIBarButtonItem按鈕的屬性兩個項目UINavigationItem,而不是UINavigationBar的

例如,當使用一個UINavigationController時,它會自動提供其自己的UINavigationBar的。但每一個由導航控制器管理可以定義一個UINavigationItem,它控制的標題,視圖左和右按鈕等

0

更新:iOS 5的支持在同一側上多個按鈕。從UINavigationItem文檔:

自定義視圖

titleView property 
    leftBarButtonItems property 
    leftBarButtonItem property 
    rightBarButtonItems property 
    rightBarButtonItem property 
– setLeftBarButtonItems:animated: 
– setLeftBarButtonItem:animated: 
– setRightBarButtonItems:animated: 
– setRightBarButtonItem:animated: 

所以,基本上,你會寫這樣的事情在左邊添加兩個按鈕:

UIBarButtonItem *refreshBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshPlans:)]; 
UIBarButtonItem *selectYearBtn = [[UIBarButtonItem alloc] initWithTitle:@"Select Year" style:UIBarButtonSystemItemAction target:self action:@selector(selectYear)]; 
self.navigationItem.leftBarButtonItems = [[NSArray alloc] initWithObjects: refreshBtn, selectYearBtn, nil]; 

不幸的是,我的天堂」沒有看到在故事板中執行此操作的方法。希望這可以幫助。