1

I found several posts online stating that I could access my application delegate object from any view controller through the following call:

[[UIApplication sharedApplicaton] delegate];

(For instance: data between Views UIApplication, iOS - Calling App Delegate method from ViewController)

However, whenever I include this line in a function in one of my view controllers, the application crashes.

This is the first application that I'm writing, and I cannot see the difference between my code and how other posts have said I should be using this sharedApplication call. For completeness, below is an excerpt from my application delegate and view controller.

FirstViewController.h:

@class wStreamAppDelegate;
#define URL_ADDRESS @"http://google.com"

@interface FirstViewController : UIViewController <UIWebViewDelegate>{
    IBOutlet UIWebView  * webView;
wStreamAppDelegate* appDelegate;
}

@property(nonatomic,retain) wStreamAppDelegate* appDelegate;
@property(nonatomic,retain) IBOutlet UIWebView* webView;

FirstViewController.m:

#import "FirstViewController.h"
#import "wStreamAppDelegate.h"

@implementation FirstViewController
@synthesize webView,appDelegate;
@class wStreamAppDelegate;

- (void)viewDidLoad {
    [super viewDidLoad];
NSString* urlAddress = URL_ADDRESS;
NSURL* url = [NSURL URLWithString:urlAddress];
NSURLRequest * requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];

    self.appDelegate = (wStreamAppDelegate*)[[UIApplication sharedApplicaton] delegate];

    //This doesn't work either
    //  wStreamAppDelegate *appDelegate= (wStreamAppDelegate*)[[UIApplication sharedApplicaton] delegate];

wStreamAppDelegate.h:

@interface wStreamAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
   UIWindow *window;
   UITabBarController *tabBarController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

@end

If anyone has any thoughts on what may be going wrong, general advice for debugging problems like these, or tips, I'd really appreciate it. Thanks.

Community
  • 1
  • 1
Behram Mistree
  • 4,088
  • 3
  • 19
  • 21
  • To start, go to Run >> Console to open the console and see what specific error is causing your problem. – aleph_null Nov 12 '11 at 06:35
  • Thanks for responding so quickly: [Session started at 2011-11-11 22:38:37 -0800.] 2011-11-11 22:38:39.032 wStream[647:207] +[UIApplication sharedApplicaton]: unrecognized selector sent to class 0x1ea2898 2011-11-11 22:38:39.036 wStream[647:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[UIApplication sharedApplicaton]: unrecognized selector sent to class 0x1ea2898' *** Call stack at first throw: – Behram Mistree Nov 12 '11 at 06:39
  • Try this... appDelegate = [[UIApplication sharedApplicaton] delegate]; – Sahil Khanna Nov 12 '11 at 06:48

1 Answers1

0

Typos get everyone sooner or later... in this case, you wrote "sharedApplicaton" instead of "sharedApplication".

aleph_null
  • 5,766
  • 2
  • 24
  • 39