Mohamad Afiq
Mohamad Afiq

Reputation: 275

UICollectionView Top Bar Doesn't Appear In Simulator

I had a little problem which is my uicollectionviewcontroller top bar doesn't appear in simulator and device. I already set the top bar to translucent navigation bar for uicollectionviewcontroller, then I dragged navigation item to navigation bar and finally I set an image for left bar button items to function as back button. Below is there screenshot.

Top Bar Storyboard:

Storyboard

Simulator Result:

Simulator

Upvotes: 1

Views: 96

Answers (2)

Tim
Tim

Reputation: 2098

To add the navigation controller (which will add the bar), highlight the UICollectionViewController in storyboard, and select Editor->Embed in->Navigation Controller from the menus.

Upvotes: 0

Nicholas Langley
Nicholas Langley

Reputation: 73

It doesn't look like you have a navigation controller, to add a navigation bar programatically without a navigation controller controlling the view hierarchy you can do the following.

-(void) viewWillAppear:(BOOL)animated {

    UINavigationBar *navBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
    [UINavigationBar appearance].barTintColor = [UIColor lightGrayColor];
    [self.view addSubview: navBar];


    UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel"
                                                               style:UIBarButtonItemStyleBordered
                                                              target:self
                                                              action:nil];

    UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                             style:UIBarButtonItemStyleBordered
                                                            target:self action:nil];


    UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:@"Navigation Title"];

    navItem.rightBarButtonItem = doneItem;
    navItem.leftBarButtonItem = cancelItem;
    navBar.items = [NSArray arrayWithObjects: navItem,nil];

    [UIBarButtonItem appearance].tintColor = [UIColor blueColor];

}

Upvotes: 1

Related Questions