【发布时间】:2025-12-19 14:55:06
【问题描述】:
更新的问题: 你好,所以我能够为此用途创建模态视图卷曲覆盖。但是我现在有一个问题,我可以单击 button1 并在 webView1 上使用 url1 拉出第二个视图,但是当我单击 button2 时,我也会在 webview 上收到 url1 的显示。下面是代码你能帮我解决我做错了什么吗?
FourthViewController.h 代码如下:
'
#import <UIKit/UIKit.h>
@interface FourthViewController : UIViewController {
UIButton *openBlogButton, *openFbButton, *openYelpButton;
}
@property (nonatomic, retain) IBOutlet UIButton *openBlogButton, *openFbButton, *openYelpButton;
-(IBAction)openBlog:(id)sender;
-(IBAction)openFacebook:(id)sender;
-(IBAction)openYelp:(id)sender;
@end
'
FourthViewController.m 代码如下:
'
#import "FourthViewController.h"
#import "FourthBlogWebViewController.h"
#import "FourthFBWebViewController.h"
@implementation FourthViewController
@synthesize openBlogButton, openFbButton, openYelpButton;
-(IBAction)openBlog:(id)sender {
FourthBlogWebViewController *sampleView = [[[FourthBlogWebViewController alloc] init] autorelease];
[sampleView setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self presentModalViewController:sampleView animated:YES];
}
//THIS IS WHERE I THINK THE ISSUE IS, WHEN I CLICK openFacebook it should lead to the fb URL, it seems as if I should be able to list all possible urls on the first fourthwebviewcontroller, but i was not able to be successful so I tried making a second webview controller to feed it this url but this failed...lol. thnx for any input.
-(IBAction)openFacebook:(id)sender {
FourthFBWebViewController *sampleView = [[[FourthFBWebViewController alloc] init] autorelease];
[sampleView setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self presentModalViewController:sampleView animated:YES];
}
-(IBAction)openYelp {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.yelp.com"]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (void)dealloc {
[openBlogButton release];
[openFbButton release];
[openYelpButton release];
[super dealloc];
}
@end
'
FourthBlogWevViewController.h
'
#import <UIKit/UIKit.h>
@interface FourthBlogWebViewController : UIViewController {
UIButton *dismissViewButton;
IBOutlet UIWebView *webViewFB;
}
@property (nonatomic, retain) IBOutlet UIButton *dismissViewButton;
@property (nonatomic, retain) UIWebView *webViewFB;
- (IBAction)dismissView:(id)sender;
@end'
FourthBlogWebViewController.m code:
'#import "FourthBlogWebViewController.h"
@implementation FourthBlogWebViewController
@synthesize dismissViewButton, webViewFB;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
}
return self;
}
-(IBAction)dismissView:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
- (void)viewDidLoad {
NSString *urlAddress = @"http://www.facebook.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webViewFB loadRequest:requestObj];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (void)dealloc {
[dismissViewButton release];
[webViewFB release];
[super dealloc];
}
@end
我将在何处或如何添加第二个 url 并使其在单击其他按钮时进行区分。提前感谢您一直以来的帮助。
原问题: 你好,
所以第一个应用程序,我正在尝试使用按钮的一些基本功能,我在标签栏应用程序中执行此操作。在我的第四个选项卡视图中,打开一个带有 3 个按钮的视图,单击该按钮时,我试图在应用程序中加载一个网页(我能够通过 safari 在单击按钮内的按钮修饰上成功打开网页,但是不是我希望它加载的方式。所以我编辑了它的加载方式,按下按钮,网站现在在 webView 中打开。但是我想在新视图上创建这个 webview,而不是在 3按钮是,但我不清楚如何做到这一点。任何输入将不胜感激(我事先道歉,因为这似乎是一项简单的任务,但还没有弄清楚,我在询问之前做了一些搜索,但是无法找到任何显示如何在按下不同按钮以在同一 XIB 内的新视图上加载 web 视图时执行此操作的任何内容。
谢谢。
下面是我在按下按钮时加载 webview 的代码。
在第四视图控制器.h
#import <UIKit/UIKit.h>
@interface FourthViewController : UIViewController {
IBOutlet UIWebView *webView;
}
-(IBAction)openWebsite:(id)sender;
-(IBAction)openButton2;
-(IBAction)openButton3;
@property (nonatomic, retain) UIWebView *webView;
@end
在第四视图控制器.m
#import "FourthViewController.h"
@implementation FourthViewController
@synthesize webView;
-(IBAction)openWebsite:(id)sender{
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.URL.com"]]];
}
-(IBAction)openButton2:(id)sender{
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.URL2.com"]]];
}
-(IBAction)openButton3:(id)sender{
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.URL3.com"]]];
}
基本上,我试图让不同的按钮推送到同一个新视图,但唯一的区别是我希望 uiwebview 根据带来新视图的按钮单击显示不同的 URL。
【问题讨论】:
-
在你得到这个答案之前,它会帮助你知道你是否想像 UINavigationController 那样将新视图推送到屏幕上,或者如果你想将它添加为像 presentModalViewController 这样的模态覆盖:animated: 做到了。
-
感谢您的提问,我最初的想法是按照导航控制器的方式推送视图,但是在研究了模态叠加替代方案之后,这实际上会更好。提前感谢您提供的任何帮助。
-
所以我想出了如何进行模态叠加视图,但遇到了第二个问题。如下所列。
标签: iphone xcode ios4 uiwebview interface-builder