2个按钮点击的Web视图

时间:2014-09-16 15:33:07

标签: ios objective-c uiwebview

大家好我是xcode的新手,我正在使用 xcode 5.1我的项目有一个像主视图的视图,这个视图有6个按钮,其中2个打开webView,在互联网上搜索我发现了如何打开单个Web视图的例子,但我的问题是我需要打开1个以上的web看来,也许我的问题很愚蠢......但是如何点击按钮打开2个webView?

这是我的代码

ViewController.h

#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIWebView *supWebView;
@property (strong, nonatomic) IBOutlet UIWebView *serviciosWebView;
- (IBAction)servicios:(id)sender;
- (IBAction)support:(id)sender;
@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize supWebView;
@synthesize serviciosWebView;
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [super viewDidLoad];
    //aki para que funcione uno
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)support:(id)sender{
    NSURL *url = [NSURL URLWithString:@"https://xxx.xx/conectar.html"];
    NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
    [supWebView loadRequest:requestURL];
}
- (IBAction)servicios:(id)sender {
    NSURL *url = [NSURL URLWithString:@"https://xxx.xx/servicios.html"];
    NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
    [serviciosWebView loadRequest:requestURL];
}

@end

我不知道是否需要在app delegate中声明一些东西,我遵循一些教程并且它说它不需要。我用push连接我的按钮去另一个视图。

有人可以指导我吗? y.y

1 个答案:

答案 0 :(得分:0)

如果我理解这一点(2个网页浏览,每个网页在不同的按钮操作上加载不同的网址),你就会在错误的webView上为servicios调用loadRequest。您的服务方法:方法应如下:

- (IBAction)servicios:(id)sender {   
    NSURL *url = [NSURL URLWithString:@"https://xxxxx.xxxx/servicios.html"];
    NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
    [serviciosWebView loadRequest:requestURL];   
}