No known instance method for selector

穿精又带淫゛_ 提交于 2019-12-05 12:17:57

You will need to cast the delegate object that you get as:

AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];

Then call the method on appDelegate

Change your goSecondClicked action method to this:

- (IBAction)goSecondClicked:(id)sender 
{
    [[[UIApplication sharedApplication] delegate] performSelector:@selector(showSecondViewController)];
}

EDIT: although this alternative works for the given situation, it should be noted that the compiler won't help you if you change the method name in your delegate and forget to change the name on the selector call. So, this should be used carefully.

You can also define this macro on your AppDelegate.h

#define APP_DELEGATE (AppDelegate *)[[UIApplication sharedApplication] delegate]

After this, you can invoke your selector with:

[APP_DELEGATE showSecondViewController];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!