[英]xcode Expected Selector for objective-c method and Missing @end errors
[英]Objective-C: Compiler Errors Passing Self to Method in a Selector
所以,我试图在另一个对象中调用一个方法,并将调用对象作为调用的一部分传递。 可能是我构建它的方式毫无意义,但无论如何这是电话:
NSTimer *refreshTimer = [NSTimer
scheduledTimerWithTimeInterval:[timerDate timeIntervalSinceNow]
target:otherObject
selector:@selector(methodBeingCalled:self)
userInfo:nil
repeats:NO];
并且接收方法具有以下签名:
- (void)methodBeingCalled:(id)sender;
当我这样做时,我在调用时收到错误,上面写着“错误预期”:'“。 这对我来说没有意义,因为我在那里有一个冒号来传递“自我”作为参数。
我错误地使用了选择器吗? 我应该使用NSInvocation吗?
您无法设置这样的参数。 选择器仅定义签名以及函数具有多少个参数。 删除self
,因为你无法发送它。 如果要传递self
,请在userInfo
。 NSTimer
方法中的对象是NSTimer
本身。
PS 文档是你的朋友。 它明确指出(对于selector参数)“选择器必须对应于返回void并接受单个参数的方法。计时器将自身作为此方法的参数传递。”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.