所以我有一个 UIViewController(主应用程序控制器是 TabBarController)。在这上面有一个 UINavigationBar 和一个 UIBarButtonItem。我很确定我在 Interface Builder 中正确连接了所有内容,并且代码中的插座已连接到 .xib 中的按钮。应该是因为方法正常。
现在我在这个视图上有另一个按钮,它显示了第二个视图,一个 UIWebView。我希望这个标有“Back”的 UIBarButtonItem 使 UIWebView 消失,并带回它正确执行的第一个 UIView。但是,当您在第一个 UIView 上时,不需要看到 UIBarButtonItem,那么我该如何隐藏它,然后为 UIWebView 将其显示出来。顺便说一句,两个视图都使用相同的 UINavigationBar,UIWebView 在标签栏和导航栏内被调出。
这是我的代码:
#import "WebViewController.h"
@implementation WebViewController
@synthesize webButton;
@synthesize item;
@synthesize infoView;
UIWebView *webView;
+ (UIColor*)myColor1 {
return [UIColor colorWithRed:0.0f/255.0f green:76.0f/255.0f blue:29.0f/255.0f alpha:1.0f];
}
// Creates Nav Bar with default Green at top of screen with given String as title
+ (UINavigationBar*)myNavBar1: (NSString*)input {
UIView *test = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, test.bounds.size.width, 45)];
navBar.tintColor = [WebViewController myColor1];
UINavigationItem *navItem;
navItem = [UINavigationItem alloc];
navItem.title = input;
[navBar pushNavigationItem:navItem animated:false];
return navBar;
}
- (IBAction) pushWebButton {
self.navigationItem.rightBarButtonItem = item;
CGRect webFrame = CGRectMake(0.0, 45.0, 320.0, 365.0);
webView = [[UIWebView alloc] initWithFrame:webFrame];
[webView setBackgroundColor:[UIColor whiteColor]];
NSString *urlAddress = @"http://www.independencenavigator.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
webView.scalesPageToFit = YES;
[webView loadRequest:requestObj];
[self.view addSubview:webView];
[webView release];
}
- (void) pushBackButton {
[webView removeFromSuperview];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
self.navigationItem.rightBarButtonItem = nil;
[super viewDidLoad];
}
@end
有人知道吗?