0

I think I have a simple issue with my app. First of all I am using the PraseSDK in order to use the LoginView they offer.

Now I was going to create that function and let it called by a view controller in

-(void) viewDidLoad

It worked perfectly.

Now I was wondering if I can put that code into a global function class?

Well I created a Class called: glo_function Inside of it I created a function which is call

+(void) CallLoginScreen{
PFLogInViewController *login = [[PFLogInViewController alloc] init];
login.fields = PFLogInFieldsUsernameAndPassword | PFLogInFieldsLogInButton;
 [self presentModalViewController:login animated:NO];}

In My ViewController Iam using "callLoginScreen" like this

[glo_function CallLoginScreen]

The methode is going to be called by the View Controller but the view will not show up. Well I get that error will trying to run the app.

No known class method for selector 'presentModalViewController:animated:'

So I am pretty sure It do to the fact that I used the "self" in->

[self presentModalViewController:login animated:NO]

Can someone help me out with it? should be easy, hopefully :)

-----------------------Response------------------------------

Hi after I did that, the app crashes. The Call methode looks like that:

    [glo_function showLoginScreenUsingViewController];

In glo_function.m the methode looks like that:

+ (void)showLoginScreenUsingViewController:(UIViewController *)VC {
PFLogInViewController *login = [[PFLogInViewController alloc] init];
login.fields = PFLogInFieldsUsernameAndPassword | PFLogInFieldsLogInButton;
[VC presentModalViewController:login animated:NO];}

The Result when starting the App:

2012-12-28 21:20:24.003 Logbuch40[1942:c07] 
*** Terminating app due to uncaught exception 'NSInvalidArgumentException'
, reason: '+[glo_function showLoginScreenUsingViewController]: 
unrecognized selector sent to class 0x22e9ec

1 Answer 1

2

"self" always refers to the object you are in. In your case it's the glo_function object. So when you say self you are talking to the wrong object.

You could still do what you want but in your glo_function method you need to pass in a reference to your view controller. Then just use that in your function instead of self.

+ (void)showLoginScreenUsingViewController:(UIViewController *)VC {
     PFLogInViewController *login = [[PFLogInViewController alloc] init];
     login.fields = PFLogInFieldsUsernameAndPassword | PFLogInFieldsLogInButton;
     [VC presentModalViewController:login animated:NO];
}
3
  • OK thats what I thought! Well I just need to know how to do that! :)
    – Phill
    Dec 28, 2012 at 15:56
  • After I debuged a bit more I found out that the method is not called and the App crashes before entering the method showLoginScreenUsingViewController. So I think the problem is in Line: [glo_function showLoginScreenUsingViewController];
    – Phill
    Dec 28, 2012 at 20:48
  • Found my problem! in my glo_function.h I forgot to change the method name. After I did that I changed the call method to: [GlobaleFunction showLoginScreenUsingViewController:self]; Thank you very much! :) Problem solved! :)
    – Phill
    Dec 28, 2012 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.