【发布时间】:2015-08-06 12:34:50
【问题描述】:
我遇到了 UINavigationBar 的问题,当我在那里添加 UIButton 并运行应用程序时,我可以在 UINavigationBar 顶部看到一个额外的 UINaviagtionBar 叠加层。
请帮忙
结构是这样的
UITabbarController -> UINavigationController -->UIViewController
我已附上截图链接
运行时间[![[1]][1]][1]
[navigationcontroller->viewcontroller 屏幕][3]
代码
ViewDidAppear()
UIImage *myImage = [UIImage imageNamed:@"filter.png"];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
[myButton setImage:myImage forState:UIControlStateNormal];
myButton.showsTouchWhenHighlighted = YES;
myButton.frame = CGRectMake(0.0, 0.0,25,25);
[myButton addTarget:self action:@selector(refreshSection) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:myButton];
self.navigationItem.leftBarButtonItem = rightButton;
UIImage *myImage1 = [UIImage imageNamed:@"Contacts.png"];
UIButton *myButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
[myButton1 setImage:myImage1 forState:UIControlStateNormal];
myButton1.showsTouchWhenHighlighted = YES;
myButton1.frame = CGRectMake(0.0, 0.0,30,30);
[myButton1 addTarget:self action:@selector(profile) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightButton1 = [[UIBarButtonItem alloc] initWithCustomView:myButton1];
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:rightButton1, nil]];
【问题讨论】:
-
请发布您的 xcode 项目的更好的屏幕截图。您是否将视图控制器嵌入到导航控制器中?还是您手动将导航栏添加到 View 控制器中?
-
是的,嵌入了导航控制器
-
看看这个帖子有没有帮助:stackoverflow.com/questions/11199227/…
-
好的,让我检查一下
标签: ios objective-c uinavigationcontroller uibutton uinavigationbar