【问题标题】:how to call two url in one webview in iphone如何在iphone的一个webview中调用两个url
【发布时间】:2011-10-07 13:47:34
【问题描述】:

我想在一个 webview 中一个接一个地调用两个 url 但我怎么知道我可以在 webview 中加载一个 url 但要调用两个 url 请帮助我一个如何在两个 url 上设置时间间隔 这是 mu 单个 url 如果但我必须在这里给出两个 url 如何给和调用它们

- (void)viewDidLoad {
    [super viewDidLoad];
    CheapFlightsAppDelegate* app=(CheapFlightsAppDelegate*)[[UIApplication sharedApplication]delegate];
    self.navigationController.navigationBarHidden = true;

    NSLog(@"Book: %@",app.selectedOutgoingFlight.FlightKey);
    NSLog(@"Book: %@",app.selectedInComingFlight.FlightKey);

    NSString *hel = @"http://www.bookryanair.com/SkySales/FRSelect.aspx?AvailabilityInputFRSelectView %24ButtonSubmit=Select%20and%20Continue&AvailabilityInputFRSelectView%24m arket1="; 
    NSString *hel1 =[NSString stringWithFormat:@"%@&",app.selectedOutgoingFlight.FlightKey];
    NSString *hel2 = @"AvailabilityInputFRSelectView%24market2="; 
    NSString *hel3 = [NSString stringWithFormat:@"%@&",app.selectedInComingFlight.FlightKey]; 
    NSString *hel4 = @"__EVENTARGUMENT=&__EVENTTARGET=";



    NSString *urlAddress = [NSString stringWithFormat:@"%@%@%@%@%@",hel,hel1,hel2,hel3,hel4];
    [spinner startAnimating];
    spinner.hidden = NO;
    //Create a URL object.
    NSURL *url = [NSURL URLWithString:urlAddress];
    NSLog(@"Book: %@",urlAddress);

    //URL Requst Object
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    //Load the request in the UIWebView.
    [webView loadRequest:requestObj];
    webView.delegate = self;

}

【问题讨论】:

  • 嘿,rokey 使用新答案,它工作正常

标签: iphone objective-c


【解决方案1】:
 use this method
   NSURLRequest *request=[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:@"http://stackoverflow.com/questions/7670889/how-to-call-two-url-in-one-webview-in-iphone/7670992#7670992"]];
     [webView loadRequest:request];
     [self performSelector:@selector(loadAnother:) withObject:nil afterDelay:10];

-(IBAction)loadAnother:(id)sender{
     NSURLRequest *requests=[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:@"http://stackoverflow.com/questions/7683196/uitableview-with-text-that-is-both-right-aligned-and-indented"]];
    [webView loadRequest:requests];
}

【讨论】:

    【解决方案2】:

    设置新的urlNSURLRequest 并在您想要的任何时间间隔后再次调用[webView loadRequest:requestObj];

    NSTimer 将帮助您在一段时间后调用方法。

    // after loading first url:
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(loadNewUrl:) userInfo:nil repeats:NO];
    
    //somewhere in delegate define selector
    - (IBAction)loadNewUrl:(NSTimer *)timer
    {
         NSURL *url = [NSURL URLWithString:@"http://www.apple.com/stevejobs"];
    
         //URL Requst Object
         NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    
         //Load the request in the UIWebView.
         [webView loadRequest:requestObj];
    }
    

    更新: 在你的``方法中实现以检测 webview 何时完成加载第一个 url:

    - (void)webViewDidFinishLoad:(UIWebView *)webView;
    - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;
    

    【讨论】:

    • 如何在两者中给出时间间隔请告诉我
    • 在调用第二个 url 之前我怎么知道第一个 url 是完整的
    • 朋友只有第一个网址正在加载第二个网址没有加载
    【解决方案3】:

    在“webViewDidFinishLoad”委托方法中获取当前使用的 URL 加载

    currentURL = webView.request.URL.absoluteString;

    然后检查它是否与您的第一个 URL 匹配,如果匹配,则加载您需要调用的第二个 URL。如果需要,请在一段时间后使用计时器调用第二个 URL。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-31
      • 2017-06-12
      • 1970-01-01
      • 2018-10-25
      • 2018-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多