簡體   English   中英

在UITableViewControler中未設置導航欄標題和后退按鈕

[英]Navigation bar Title not set and back button not disable in UITableViewControler

我在情節提要中使用UITableViewController。

    [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中使用。

我使用情節提要板創建了簡單的場景:uinavigation控制器-> uiviewcontroller-> uitableviewController。

代碼可在uiviewcontroller和uitableviewController上運行。

因此,我建議您檢查以下內容:

  1. 您的uitableviewcontroller嵌入了uinavigationController;
  2. 您的Segue類型對於Xcode 6是Show(例如Push),對於較舊的版本是Push
  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;
}

當然,您可以僅出於修改裝飾參數(例如顏色或字體名稱/大小)的目的使用此代碼段

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM