0

I have 3 views that need to load web pages, I am doing the following ( with the associated connection and webview delegates ) in each of the views, is there a way to create a single source without duplicating the code in each view ? Most solutions I have found say to use asihttp but my company discourages 3rd party components. ( I'm still learning so be kind )

- (void)loadPage:(NSString*)urlString
{

  NSURL *url = [NSURL URLWithString:urlString];

  // Put that URL into an NSURLRequest
  NSURLRequest *req = [NSURLRequest requestWithURL:url];
  // NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString     stringWithFormat:urlString]]];

  // Create a connection that will exchange this request for data from the URL
  connection = [[NSURLConnection alloc] initWithRequest:req 
                                             delegate:self 
                                     startImmediately:YES];

  [self.webView loadRequest:req];

}
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
cmhdev
  • 43
  • 8

1 Answers1

0

there a way to create a single source without duplicating the code in each view ?

Maybe creating a base class containing your loadPage method and then deriving 3 classes from it for each of the views you need?

sergio
  • 68,819
  • 11
  • 102
  • 123