Kiley
Kiley

Reputation: 419

Objective-C: using methods from other files

I have looked at all the other people who had this error pop up, and I know it is a pathing error, and yes I have tried to quit and reboot it, I checked the paths were using up-to-date files, and most of what people suggested with no success. I am trying to get methods from TapViewController to run in JumpController. I simplified the method I want to be called to make it easier to find the issue, but still am having trouble. Here is the relevant code I have so far:

TapViewController.h

-(void)hello;

TapViewController.m

-(void)hello {
    NSLog(@"Hello");
}

JumpController.h

#import <UIKit/UIKit.h>
#import 'TapViewController.h'

@property (strong, nonatomic) TapViewController *TapView;
@property (strong, nonatomic) JumpController *JumpControl;

JumpController.m

-(void)viewDidLoad {
     self.JumpControl = (TapViewController *)[UIApplication sharedApplication].delegate;
     self.TapView = [[TapViewController alloc] init];
     [self.JumpControl.TapView hello];
}

I grabbed most of this code from what others have said to do, so I don't really know if some of it is irrelevant or if all will help in the situation. Basically, the app crashes when it loads stating [AppDelegate TapView]: unrecognized selector sent to instance.... Let me know if I am doing anything wrong or if I left out relevant code!

UPDATE: Using what others have said and from my own personal changes, It seems like the problem is not only with self.JumpControl = (TapViewController *)[UIApplication sharedApplication].delegate but also with self.JumpControl as a whole. Because I created the TapViewController *TapView in the .h file there is no reason to use self.JumpControl which caused problems on the order of views that showed up. I will mark almas as correct, but I wanted to clarify what more needed to be done.

Upvotes: 1

Views: 76

Answers (1)

almas
almas

Reputation: 7187

Your problem is here: "self.JumpControl = (TapViewController *)[UIApplication sharedApplication].delegate;". You are trying to cast your AppDelegate to TapViewController, thats why it crashes. AppDelegate is not a view controller. Your error message [AppDelegate TapView]: unrecognized selector sent to instance clearly states that AppDelegate doesn't recognize the method "TapView", it is because app delegate is not an instance of "TapViewController".

Upvotes: 1

Related Questions