Objective-c 如何在参数中发送(void)?
我想知道如何传入参数 void 的“地址”?
- (void) showWithLabel:(id)method {
...
[HUD showWhileExecuting:@selector(method) onTarget:self withObject:nil animated:YES];
}
- (void) test:{
sleep(3)
}
- (void) hello:{
[self showWithLabel:(id)test]
}
但这不起作用(构建错误)
i would like to know how can i pass in parameter the "address" of a void ?
- (void) showWithLabel:(id)method {
...
[HUD showWhileExecuting:@selector(method) onTarget:self withObject:nil animated:YES];
}
- (void) test:{
sleep(3)
}
- (void) hello:{
[self showWithLabel:(id)test]
}
But that doesnt work (build error)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另请注意,我删除了
test
和hello
方法中的冒号。在 Obj-C 中,冒号描述方法参数,并且由于没有参数,因此不需要冒号。Also notice that I removed the colons on your
test
andhello
methods. In Obj-C a colon delineates method parameters and since you had no parameters, you need no colons.要传递选择器,您需要以下关键字:
@selector 和 SEL。
因此,在您的示例中,它应该是:
并
调用选择器:
[target PerformSelector:method]
正如 Kubi 指出的,你应该非常小心冒号。
如果没有参数,则没有冒号。
但是,如果您有参数,您必须意识到冒号是选择器名称的一部分。
例如:
To pass a selector, you need the following keywords :
@selector and SEL.
So, in your example, it should be:
and
To call the selector :
[target performSelector:method]
As Kubi points out, you should be very careful with the colon.
There is no colon if there is no parameter.
BUT, if you have parameters, you must realize that the colon is a part of the selector's name.
For example:
不存在“空”这样的东西。
void
是一个 C 关键字,当应用于指针时,意味着该指针是无类型的,即类型未知或不重要。我最近注意到一些初学者似乎将 void 方法或函数(即不返回值的方法或函数)称为“void”,但这不是常见用法。我无法从您发布的代码中看出您想要传递什么或想要传递到哪里。您能否修改您的问题以使其更清楚?
There's no such thing as "a void".
void
is a C keyword that, when applied to a pointer, means that the pointer is untyped, i.e. the type is unknown or not important. I've noticed recently that some beginners seem to refer to a void method or function (that is, a method or function that doesn't return a value) as "a void", but this is not common usage.I can't tell from the code you posted what you want to pass or where you'd like to pass it. Could you revise your question to make it more clear?