2015-08-12 6 views
0

У меня есть два UIwebViews. Я закодировал каждого, чтобы перейти на другой URL-адрес веб-страницы. Но оба они идут к первому URL (http://test.bithumor.co/test26.php)

Вот код от просмотра controller.mСоздать отдельные UIwebViews

//  
// ViewController.m  
// BitHumor  
//  
// Created by danny rodriguez on 7/26/15.  
// Copyright (c) 2015 BitDeveloping. All rights reserved.  
//  

#import "ViewController.h" 



@interface ViewController() 

@property (strong, nonatomic) IBOutlet UIWebView *webView; 

@property (weak, nonatomic) IBOutlet UIWebView *webView2; 




@end 



@implementation ViewController 

- (void)viewDidLoad { 


    [super viewDidLoad]; 

    UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)]; 


    NSString *[email protected]"http://test.bithumor.co/test26.php"; 

    NSURL *nsurl=[NSURL URLWithString:url]; 

    NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl]; 

    [webview loadRequest:nsrequest]; 

    [self.view addSubview:webview]; 

    // Do any additional setup after loading the view, typically from a nib. 
    UIWebView *webview2=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)]; 
    NSString *[email protected]"http://google.com"; 
    NSURL *nsurl2=[NSURL URLWithString:url2]; 
    NSURLRequest *nsrequest2=[NSURLRequest requestWithURL:nsurl2]; 
    [webview2 loadRequest:nsrequest2]; 

} 



- (void)didReceiveMemoryWarning { 

    [super didReceiveMemoryWarning]; 

    // Dispose of any resources that can be recreated. 

} 

@end 

Оба веб мнения связаны с @property, как я делаю каждый из них идут к их назначенные URL-адреса веб-страницы? (Пожалуйста, скажите мне, шаг за шагом, как я новичок в кодировании Objective-C)

ответ

0

Похоже, вы уже создали IBOutlets для UIWebViews убедитесь, чтобы определить их как weak, вы определили одну из них, как Strong и другой как weak , ошибка, которую вы сделали, создает третий UIWebView, который вы добавили как subview. Это будет охватывать весь вид выше ваших двух uiwebviews.

 //Not required, remove this code 
    UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)]; 
    [self.view addSubview:webview]; 

Теперь просто создать два запроса и загрузить их в UIWebViews

 //For webview 1 
     NSString *[email protected]"http://test.bithumor.co/test26.php"; 
     NSURL *nsurl=[NSURL URLWithString:url]; 
     NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl]; 
     [self.webView loadRequest:nsrequest]; 

     //For webview 2 
     NSString *[email protected]"http://google.com"; 
     NSURL *nsurl2=[NSURL URLWithString:url2]; 
     NSURLRequest *nsrequest2=[NSURLRequest requestWithURL:nsurl2]; 
     [self.webView2 loadRequest:nsrequest2]; 
+0

[webview2 loadRequest: nsrequest2]; Я получил сообщение об ошибке «Использование необъявленного идентификатора« webview2 »: вы имели в виду« webview »?» « –

+0

use webView и webView2 отредактировали мой ответ и удалили этот код [self.view addSubview: webview]; – prasad

+0

Что вы имеете в виду под управлением webView и WebView 2? Я уже удалил: [self.view addSubview: webview]; Вот как это выглядит: http://i.stack.imgur.com/1JMd6.png –

Смежные вопросы