kiran
kiran

Reputation: 4409

Inital load view controller will not response to web view

I have two view controller one is informationViewController and another InformationDetailedViewController. there are two button on button action i am loading respective url pdf files

// InformationViewController.m
       // About Us button clicked
        -(void)aboutUsAction:(id)sender{
            [informationDetailedViewController showInformation:0];
            [self.navigationController pushViewController:informationDetailedViewController animated:YES];
        }

        // Terms and condition button clicked
        -(void)termsAndConditionAction:(id)sender{
            [informationDetailedViewController showInformation:1];
            [self.navigationController pushViewController:informationDetailedViewController animated:YES];
        }

  // InformationDetailedViewController.m    
    - (void)viewDidLoad{

        [super viewDidLoad];    
        // create a webview
        webInfoDetailed = [[UIWebView alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height)];
        webInfoDetailed.scalesPageToFit = YES;
        [webInfoDetailed setBackgroundColor:[UIColor whiteColor]];
        [self.view addSubview:webInfoDetailed];    
    }

    -(void)viewWillAppear:(BOOL)animated{
        [super viewWillAppear:YES];
    }


    -(void)viewDidAppear:(BOOL)animated{
        [super viewDidAppear:YES];
    }

        // InInformationDetailedViewController.1
        -(void)showInformation:(int )informationId {

            NSString *informationType = @"";
            switch (informationId) {
                case 0:
                    self.title = @"About Us";
                    informationType = KHABOUTUS;
                    break;
                case 1:
                    self.title = @"Disclaimer";

                    informationType = KHDISCLAIMER;
                    break;
                default:
                    break;
            }

            NSURL *targetURL = [NSURL URLWithString:informationType];
            NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
            [webInfoDetailed loadRequest:request];
        }

The issue is on initial load (first time load ) url is not loading on webView. When click back and then click AboutUs or Terms and Condition its working perfectly. Its very small thing i am missing here. @All Thanks In Advance

Upvotes: 0

Views: 134

Answers (1)

ohannes
ohannes

Reputation: 514

Expanding Jassi's comment, here is a code snippet that may help you.

In

InformationDetailedViewController.h

@property int informationId; // make it as a member of VC.

Change showInformation method such that it uses the informationId member instead of parameter in

In InformationDetailedViewController.m

-(void)showInformation { //you can omit the parameter, and do not forget to change the declaration in header file
  NSString *informationType = @"";
  switch (self.informationId) {
    case 0:
      self.title = @"About Us";
      informationType = KHABOUTUS;
    break;
    case 1:
      self.title = @"Disclaimer";
      informationType = KHDISCLAIMER;
    break;
    default:
    break;
  }

  NSURL *targetURL = [NSURL URLWithString:informationType];
  NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
  [webInfoDetailed loadRequest:request];
}

Finally, replace the call for showInformation method in

InformationViewController.m

        // About Us button clicked
        -(void)aboutUsAction:(id)sender{
            [informationDetailedViewController setInformationId:0];
            [self.navigationController pushViewController:informationDetailedViewController animated:YES];
        }

        // Terms and condition button clicked
        -(void)termsAndConditionAction:(id)sender{
            [informationDetailedViewController setInformationId:1];
            [self.navigationController pushViewController:informationDetailedViewController animated:YES];
        }

Hope it helps.

Upvotes: 1

Related Questions