2015-06-22 70 views
0

我在故事板中使用UITableViewController。導航欄標題沒有設置和後退按鈕不禁用在UITableViewControler

[self.navigationController setNavigationBarHidden:NO animated:NO]; 
    [self.navigationItem setHidesBackButton:YES animated:YES]; 

    UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back2.png"] style:UIBarButtonItemStylePlain target:self action:@selector(back:)]; 
    self.navigationItem.leftBarButtonItem = editButton; 

    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}]; 

    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:(44/255.0f) green:(165/255.0f) blue:(264/255.0f) alpha:(1.0f)]]; 

    [self.navigationItem setTitle:@"SETTINGS"]; 

    self.navigationController.navigationBar.tintColor = [UIColor whiteColor]; 

問題是我想隱藏後退按鈕和標題不顯示在導航欄中。相同的代碼在UIViewcontroller中起作用。

+0

你究竟在哪裏放置這段代碼?在哪個方法? –

+0

如果你沒有發現問題,也許只是使用一個UIViewController,並把一個ViewController裏面。這些變化很小,UIViewController稍後會給你更多的靈活性(以我的經驗..) –

+0

我把這段代碼放在viewWillApear方法中。 – Singh

回答

0

我使用storyboard創建了簡單場景:uinavigation controller - > uiviewcontroller - > uitableviewController。

代碼適用於uiviewcontroller和uitableviewController。

所以,我建議你檢查下一個事情:

  1. 您的UITableViewController內嵌有UINavigationController的;
  2. 您賽格瑞類型是展會(例如推送)的Xcode的6或推動舊版本
  3. 檢查模擬指標 - >頂欄爲適當的值(我建議推斷所有的導航鏈)

至於標題和酒吧裝飾我用這兩種方法作爲一個類別的UIViewController從標題邏輯分割裝飾邏輯

-(void)decorateNavigationBarAppearance 
{ 
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] 
                forBarMetrics:UIBarMetricsDefault]; 
    self.navigationController.navigationBar.shadowImage = [UIImage new]; 
    self.navigationController.navigationBar.translucent = YES; 
    self.navigationController.view.backgroundColor = [UIColor clearColor]; 
    self.navigationController.navigationBar.backgroundColor = [UIColor clearColor]; 
    self.navigationController.navigationBar.tintColor = RGB(255, 255, 255); 
    self.navigationController.navigationBar.shadowImage = [self imageWithColor:RGB(154, 153, 163) size:(CGSizeMake(self.view.frame.size.width, 1.0f))];  
} 

- (void) setNavigationItemTitle:(NSString *)title 
{ 

    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 310, 40)]; 
    titleLabel.text = title; 
    titleLabel.textAlignment = NSTextAlignmentLeft; 
    titleLabel.font = [UIFont fontWithName:@"ProximaNova-Bold" size:17]; 
    titleLabel.backgroundColor = [UIColor clearColor]; 
    titleLabel.textColor = RGB(255, 255, 255); 
    UIView *content = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)]; 
    [content addSubview:titleLabel]; 
    self.navigationItem.titleView = content; 
} 

當然,你可以使用該代碼段用於你的目的只是修改裝飾PARAMS例如顏色或字體名稱/大小

希望這有助於。

相關問題