Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8638445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:43:49+00:00 2026-06-12T10:43:49+00:00

I am having an issue with ARC. It is not retaining the webview. The

  • 0

I am having an issue with ARC. It is not retaining the webview. The scenario is I have to send a webview from one viewcontroller to another one. The reason is when the user searches for something I want to take him to a new screen with some other options. (I have to use the same webview)

Here is the sample code: I have a ViewController1 which has a webview (I added it in the xib.) I am loading say google in it and once the user searches for something and when its done loading I have to take him to a new view controller and show the same webview in the new viewcontroller.

//ViewController1
@interface ViewController1 : UIViewController <UIWebViewDelegate>
    @property (nonatomic, retain) UIWebView* testWebView;
@end

@implementation ViewController1
@synthesize testWebView;
- (void)viewDidLoad
{
    [super viewDidLoad];
    testWebView = [[UIWebView alloc]init];
    testWebView.delegate = self;
    [testWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.google.com"]]];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
    NSString *html = [testWebView stringByEvaluatingJavaScriptFromString: 
                      @"document.body.innerHTML"];
    if ([self.testWebView.request.url.absoluteString     rangeOfString:@"output=search"].location != NSNotFound) {
        ViewController2* newViewController = [[ViewController2 alloc] init];
        [newViewController setTestWebView:self.testWebView];
        [self.navigationController setViewControllers:[NSArray arrayWithObject:newViewController] animated:NO];
    }
}
- (void)dealloc{
    [self.testWebView stopLoading];
    self.testWebView.delegate = nil;
    self.testWebView = nil;
}

In the second view controller I am loading stackoverflow.com after a delay of 10 secs. The problem is it is loading stackoverflow fine, but it is not calling any of the delegate methods. Why?

@interface ViewController2 : UIViewController <UIWebViewDelegate>
    @property (nonatomic, retain) UIWebView* testWebView;
@end

@implementation ViewController2
@synthesize testWebView;
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.testWebView.delegate = self;
    [self.view addSubview:testWebView];
    [self performSelector:@selector(loadDifferentPage) withObject:nil afterDelay:10];
}

-(void)loadDifferentPage{
    [self.testWebView loadRequest:[NSURLRequest requestWithURL:[NSURL     URLWithString:@"http://www.stackoverflow.com/"]]];
}

-(void)webViewDidStartLoad:(UIWebView *)webView{
    NSLog(@"%s", __PRETTY_FUNCTION__);
}

-(void)webViewDidFinishLoad:(UIWebView *)webView{
    NSLog(@"%s", __PRETTY_FUNCTION__);
}

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    NSLog(@"%s", __PRETTY_FUNCTION__);
    return YES;
}

ViewController2 is retaining the webview but the delegate methods are not being called. Why?

Thanks
Sai

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:43:51+00:00Added an answer on June 12, 2026 at 10:43 am

    ViewController1 delloc method was causing the issue:

    If I uncomment out self.textWebView.delegate = nil it works fine. The reason is first we are setting the webview for newViewController and later in dealloc of ViewController1 we are setting its delegate to nil.

    - (void)dealloc{
        [self.testWebView stopLoading];
        if(self.testWebView.delegate == self)
            self.testWebView.delegate = nil;
        self.testWebView = nil;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi guys I am having issue I have this query: SELECT * FROM useraccount
I am having a issue to present to user an arc and then rectangle
Just started mongo and started having issue with querying already. i have a collection
Having an issue here that I have tried everything I can think of but
Having an issue with traversing in jQuery.. hopfully an easy one..but I'm banging my
I am having issue connecting from ROR 3.2 to Oracle database. irb(main):001:0> gem 'ruby-oci8',
I am having issue with opencv's Sobel edge detector. From its documentation it seems
I am having issue while showing a WebView in an activity in the middle
Experts, I'm having issue when sending emails out. Currently, I have a feedback form
I am having issue when sending data from Service to Activity through Notification ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.