gpt4 book ai didi

objective-c - 在Xcode中调用 "(id)sender"方法

转载 作者:搜寻专家 更新时间:2023-10-30 19:51:06 25 4
gpt4 key购买 nike

这是我希望调用的方法:

- (void)myMethod:(id)sender {

我该怎么调用它?我试过:

[self myMethod]

^错误:“]”标记前的预期表达式。

我知道这是一个简单的问题,但我是 iPhone 开发的新手

最佳答案

该方法接受一个参数,因此您必须给它一个参数。如果您没有要提供的发件人,只需传递 nil:

[self myMethod:nil];

您也可以为了方便而重载该方法:

// declarations
- (void)myMethod;
- (void)myMethod:(id)sender;

// implementations
- (void)myMethod { [self myMethod:nil]; }
- (void)myMethod:(id)sender { /* do things */ }

关于objective-c - 在Xcode中调用 "(id)sender"方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4456115/

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