user961632
user961632

Reputation: 39

subview of UIWebview is not responding to load request

I am building a web browser that creates a new UIWebview when I add another tab.Each new view is given a tag upon creation which allows me to call a specific view. When I call the subview to front it does not respond to a load request. This is how I am bringing the subview to the front

-(void) selectionMade:(id)sender
{
    //find view with same tag num as button pushed
   for (UIView *view in self.webView.subviews)
    {
        if (view.tag == [sender tag])
        {
            [self.webView bringSubviewToFront:view];
        }
    }
}

Here is the code for responding to the text field that I enter the address into.

- (void)textFieldDidEndEditing:(UITextField *)textField
{

    NSString *text = [textField.text lowercaseString];

    if (![text hasPrefix:@"http://"] && ![text hasPrefix:@"https://"])
    {
        text = [NSString stringWithFormat:@"http://%@", text];
    }

    self.title = text;
    url = [NSURL URLWithString:text];
    NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageAllowedInMemoryOnly timeoutInterval:10.];
    [self.webView loadRequest:request];

}

Upvotes: 0

Views: 427

Answers (1)

Léo Natan
Léo Natan

Reputation: 57040

You should not be adding other webviews as subviews of your webview. This is an incorrect design. Practically, what happens is you call loadRequest: on the main webview, but bring one of its subviews to front, which hides the main webview's content.

Depending on the experience you want to provide, you have several options.

  1. You can juggle webviews (similar to what you wanted to do here). But these webviews should be on the same level in the hierarchy, and they should only be brought to front as needed. Your view controller will then be the delegate of multiple webviews and will have to service them all. This is how Safari manages its views.
  2. You can create a page view controller and feed it different view controllers for each tab. This will make it more easier to manage, as each view controller will only service one tab. It will also allow you to offer a swipe from left or right to quickly switch tabs.

Upvotes: 1

Related Questions