我有一个导航控制器应用程序,我正在使用此代码切换视图:
- (IBAction)switchPage:(id)sender
{
if(self.fourthViewController == nil)
{
FourthViewController *fourthView = [[FourthViewController alloc]
initWithNibName:@"FourthView" bundle:[NSBundle mainBundle]];
self.fourthViewController = fourthView;
[fourthView release];
}
[self.navigationController pushViewController:self.fourthViewController animated:YES];
}
但是我希望有一个可以转到UIWebview的备用视图的按钮,我的目标是不离开应用程序,这样当用户在网页上完成时,导航控制器永远不会消失,他们可以继续到下一个观点。
有没有人知道可以提供帮助的教程?
答案 0 :(得分:0)
为什么不使用模态视图?这是我的一个应用程序的示例。下面是我在导航控制器导航栏上分配一个信用栏按钮项目,当点击时,它会显示提供webview的模态视图控制器。真的很简单:
UIBarButtonItem *credits = [ [ [ UIBarButtonItem alloc ]
initWithTitle:@"More"
// initWithCustomView:testLabel
style: UIBarButtonItemStylePlain
target: self
action:@selector(credits)
]
autorelease ];
self.navigationItem.rightBarButtonItem = credits;
-(void)credits {
if (self.whyModalViewController == nil)
self.whyModalViewController = [[[ModalViewController alloc] initWithAppDelegate:self ] autorelease];
NSString *html = [ [ NSString alloc ] initWithFormat:@"%@", self.explain];
NSString *imagePath = [[NSBundle mainBundle] resourcePath];
NSLog(@"imagePath = %@ ",imagePath);
imagePath = [imagePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
[self.whyModalViewController.webView loadHTMLString:html baseURL:[NSURL URLWithString: [NSString stringWithFormat:@"file:/%@//",imagePath]]];
[self presentModalViewController:whyModalViewController animated:YES];
[html release];
}
有很多方法可以回到主视图。我在webview上实现了一个“后退”按钮,它取消了模态视图控制器:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(dismissAction:) forControlEvents:UIControlEventTouchUpInside];
NSString *title = @"<- Back";
button.backgroundColor = [UIColor clearColor];
[button setTitle: title forState:UIControlStateNormal];
- (IBAction)dismissAction:(id)sender
{
[self.parentViewController dismissModalViewControllerAnimated:YES];
}