ios - UICollectionView 顶部栏未出现在模拟器中

标签 ios objective-c iphone

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

顶栏 Storyboard:

Storyboard

模拟器结果:

Simulator

最佳答案

看起来您没有导航 Controller ,要在没有导航 Controller 控制 View 层次结构的情况下以编程方式添加导航栏,您可以执行以下操作。

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

}

关于ios - UICollectionView 顶部栏未出现在模拟器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33812253/

相关文章:

objective-c - Objective-C中抽象类和接口(interface)之间的区别

ios - 在 UITableViewCell 中修改 UIView 外观的正确方法是什么?

iphone - 视频不显示在屏幕上

ios - 如何获取键盘的高度,包括 swift 4 中的建议栏

ios - 导航栏按钮未显示

iphone - 无法写入 : SSL/TLS with AsyncSocket for iOS

ios - phonegap xcode 4.3

ios - 最小化 iOS 应用程序大小

ios - 验证 iOS 的 url 以 www 开头

iphone - 将核心动画与 CALayers 以外的对象一起使用