【问题标题】:UINavigationController rightbarbuttonitem not showingUINavigationController rightbarbuttonitem没有显示
【发布时间】:2012-07-09 08:47:14
【问题描述】:

在完成与 UINavigationController 项目相关的问题后,我来发布我的确切问题.. 首先我没有在MainWindow.xib 中添加 UINavigationController 我创建并在AppDelegate 文件中添加 UINavigationController 之后在UIViewController(不在rootViewController)类中,我必须添加一个Done类型的右栏按钮我是 将其添加到 searchbarDelegate 方法中,显示为粗体:-

- (void) searchBarTextDidBeginEditing:(UISearchBar *)theSearchBar {

//This method is called again when the user clicks back from teh detail view.
//So the overlay is displayed on the results, which is something we do not want to happen.

if(exhibDataObj.searching)
    return;

//Add the overlay view.
if(ovController == nil)
    ovController = [[OverlayViewController alloc] initWithNibName:@"OverlayView" bundle:[NSBundle mainBundle]];

CGFloat yaxis = self.navigationController.navigationBar.frame.size.height;
CGFloat width = self.view.frame.size.width;
CGFloat height = self.view.frame.size.height;

//Parameters x = origion on x-axis, y = origon on y-axis.
CGRect frame = CGRectMake(0, yaxis, width, height);
ovController.view.frame = frame;    
ovController.view.backgroundColor = [UIColor grayColor];
ovController.view.alpha = 0.5;

ovController.rvController = self;

[self.theTableView insertSubview:ovController.view aboveSubview:self.parentViewController.view];

exhibDataObj.searching = true;
letUserSelectRow = NO;
self.theTableView.scrollEnabled = NO;

//Add the done button.
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] 
                                          initWithBarButtonSystemItem:UIBarButtonSystemItemDone 
                                          target:self action:@selector(doneSearching_Clicked:)];
 }

但这永远行不通。

任何帮助都会更有意义。

【问题讨论】:

  • 您尝试在哪个 iOS 版本中运行应用程序?
  • 您是否在AppdelegateUIViewController 中都添加了您的UINavigationBar
  • @Jasmine 查看问题的标签!!!
  • @nfarshchi 我在 appDelegate 文件中添加 UINavigationController 并在所有应用程序中访问它......

标签: objective-c xcode4.3 ios5


【解决方案1】:

我已经快速测试了您的代码,它似乎对我来说工作正常,但是,我曾经遇到过同样的问题,后来发现我在设置它后在 viewDidLoad 方法中将 rightBarButtonItem 设置为 nil到一个按钮。你应该确保你不会以某种方式犯同样的错误。

但是,如果这对您不起作用,您可以随时尝试为其设置自定义按钮:

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 5, 30, 30)];

button.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"done.png"]];

[button addTarget:self action:@selector(doneButtonClicked) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithCustomView:button];

self.navigationController.visibleViewController.navigationItem.rightBarButtonItem = customItem;

【讨论】:

  • 太棒了!最后一行是唯一对我有用的!谢谢”
  • 对我来说也一样,最后一行修复了它
猜你喜欢
  • 1970-01-01
  • 2015-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多