想法非常简单。我在带有自定义控件的通用故事板中有导航栏。
UIButton *menu = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
[menu setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
[menu addTarget:self.viewDeckController action:@selector(toggleLeftView) forControlEvents:UIControlEventTouchUpInside];
UIButton *refresh = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
[refresh setImage:[UIImage imageNamed:@"refresh"] forState:UIControlStateNormal];
[refresh addTarget:self action:@selector(reloadPosts) forControlEvents:UIControlEventTouchUpInside];
UIButton *share = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
[share setImage:[UIImage imageNamed:@"share"] forState:UIControlStateNormal];
[share addTarget:self action:@selector(showActionView) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *menuBtn = [[UIBarButtonItem alloc] initWithCustomView:menu];
UIBarButtonItem *refreshBtn = [[UIBarButtonItem alloc] initWithCustomView:refresh];
UIBarButtonItem *shareBtn = [[UIBarButtonItem alloc] initWithCustomView:share];
UIBarButtonItem *negativeSpacerLeft = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[negativeSpacerLeft setWidth:-10];
UIBarButtonItem *negativeSpacerRight = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[negativeSpacerRight setWidth:-10];
self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacerLeft, menuBtn, nil];
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:negativeSpacerRight, shareBtn, refreshBtn, nil];
一切正常 - 导航栏已实现样式和按钮/图标。但iPad和iOS 8存在问题(适用于iOS7)。当我点击任何按钮时,它没有响应。我做错了什么?它适用于iOS 7/8的iPhone。