Objective C Calling Method on Another Class


I have 2 classes, MainViewController and 'FooView' for example.

In MainViewController I have a method called -(void)doSearch

I'm trying to call doSearch from Foo, is see in the log "doSearch" (NSLog) but the UIWebView doesn't response.


MainViewController *mainVc = [[MainViewController alloc] init]; [mainVc doSearch];


- (void)doSearch { NSLog(@"doSearch"); [myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/"]]]; }

myWebView is a UIWebView.


Guy Dor


I think something is nil here. In Obj-C you can send messages (call methods) on a nil object without an error or exception. In your case, your MainViewController could be null in the FooView, or it is possible that something in that method is nil. For example, if have a xib file for that view controller, then it needs to be loaded with initWithNibName:bundle:. If you don't do that, then the IBOutlets will be nil (possibly the myWebView in your doSearch: method for example).


Check if "mainVc" is not nil. You are probably falling at initializing it.


if u create MainViewController with NIB file then u have to call like this.

MainViewController *mainVc = [[MainViewController alloc]initWithNibName:@"MainViewController" bundle:nil]; [mainVc doSearch];


  • UIWebview wont Display Https (iPhone)
  • Click alert button to show MFMailComposeViewController
  • XCode ios4 UIWebView Code Problem
  • Property 'frame' cannot be found in forward class
  • UIWebview disable redirect to AppStore
  • iOS - How to create WKWebView Back Button programmatically?
  • Use of undeclared identifier - Xcode
  • Objective C Calling Method on Another Class
  • android: WebView canGoBack() Error
  • Locate a html file in UIWebView
  • Android webview after onJsAlert not responding taps
  • NativeScript WebView loading local resources in src document
  • Displaying a PDF with UIWebView Not Working
  • Reachability crashes app
  • Place AdMob ad at the bottom of tableview controller - swift
  • WebView history
  • Background Loading a url in a uiwebview
  • goBack() in WebView goes back ALMOST all the way
  • POST with swift 2 on UIWebView does not work
  • Generating cookie from website that implements testcookie-nginx-module
  • Avoid UIWebView load iTunes App
  • How to get message from MessageIDTerm for Yahoo IMAP profile?
  • Writing to same file at the very same time
  • iOS 6 dateFromString returns wrong date
  • “A GKScore must specify a leaderboard.”
  • Emacs lua-mode issue: (void-function interactively-called-p)
  • Knockout custom binding handler
  • Question about instantiating object
  • NSScanner Loop Question
  • Pass value from viewmodel to script in zk
  • How to add date and time under each post in guestbook in google app engine
  • Eraser for UIBezierPath
  • Compare two NSDates in iPhone
  • Is there a mandatory requirement to switch app.yaml?
  • File upload with ng-file-upload throwing error
  • ExecuteAsync RestSharp to allow backgroundWorker CancellationPending c#
  • AngularJs get employee from factory
  • Load html files in TinyMce