gpt4 book ai didi

objective-c - 如何调用不同类中的选择器?

转载 作者:行者123 更新时间:2023-11-28 18:43:20 25 4
gpt4 key购买 nike

我正在尝试使用这段代码,但 Xcode 返回错误,因为我试图在 selector:@selector() 中调用的方法在另一个类中。感谢您的帮助!

AppDelegate.m:

-(void)applicationDidBecomeActive:(UIApplication *)application{
[..]
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethodHere) name:UIApplicationDidBecomeActiveNotification object:nil];
}

MainViewController.m:

-(void)myMethodHere{
[..]
}

最佳答案

问题是你用

addObserver:self

这意味着它在当前类中查找函数。而是做类似的事情

addObserver:instanceOfOtherClass

关于objective-c - 如何调用不同类中的选择器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8466850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com