在加载webView的时候怎么切换地址加载

来源:互联网 发布:原味丝袜淘宝店铺 编辑:程序博客网 时间:2024/05/29 10:18
@interface ViewController ()<UIWebViewDelegate>

@property (nonatomic,strong) UIWebView *webView;
@property (nonatomic,strong) NSString *str;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    button.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height - 68, 100, 40);
    button.backgroundColor = [UIColor redColor];
    [button addTarget:self action:@selector(updataWebView) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
       self.str = @"http://www.taobao.com";
    
    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 68)];
    [self.view addSubview: self.webView];
    self.webView.delegate = self;
    
    [self loadWebView];
    // Do any additional setup after loading the view, typically from a nib.
}


//点击按钮重新加载地址
-(void)updataWebView{

    
    
    
    self.str = @"http://www.baidu.com";
        
         [self loadWebView];
    

}


-(void)loadWebView{
    
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.str] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:1];
    [self.webView loadRequest:request];
}

0 0
原创粉丝点击