在完成与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:)];
}
但这从不起作用。
任何帮助都会更加明显。
答案 0 :(得分: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;