UICollectionView顶栏不会出现在模拟器中

时间:2015-11-19 19:00:44

标签: ios objective-c iphone

我有一个小问题,这是我的uicollectionviewcontroller顶栏没有出现在模拟器和设备中。我已经将顶部栏设置为uicollectionviewcontroller的半透明导航栏,然后我将导航项拖动到导航栏,最后我为左栏按钮项设置了一个图像以用作后退按钮。下面是截图。

Top Bar Storyboard:

Storyboard

模拟器结果:

Simulator

2 个答案:

答案 0 :(得分:1)

看起来您没有导航控制器,要以编程方式添加导航栏,而导航控制器无法控制视图层次结构,您可以执行以下操作。

-(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];

}

答案 1 :(得分:0)

要添加导航控制器(将添加栏),请在故事板中突出显示UICollectionViewController,然后从菜单中选择Editor->Embed in->Navigation Controller