gpt4 book ai didi

ios - 如何通过按钮选择器将字符串参数传递给另一个方法?

转载 作者:行者123 更新时间:2023-11-29 00:40:31 25 4
gpt4 key购买 nike

我有下面这个接收 stickerURLString 作为输入的委托(delegate)方法:

- (void)selectedSticker:(NSString *)stickerURLString {
//...
[self.stickerPreviewButton addTarget:self action:@selector(sendStickerPreviewButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
//...
}

选择器调用此方法sendStickerPreviewButtonPressed:

- (void)sendStickerPreviewButtonPressed: (NSString *)stickerURLString {
[self.delegate InputFunctionView:self sendSticker:stickerURLString];
}

如您所见,为了使这项工作按预期进行,我必须将 stickerURLStringselectedSticker 方法传递给 sendStickerPreviewButtonPressed。。

我试过这个:

[self.stickerPreviewButton performSelector:@selector(sendStickerPreviewButtonPressed:) withObject:stickerURLString];

而不是这个:

[self.stickerPreviewButton addTarget:self action:@selector(sendStickerPreviewButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

但是我遇到了“终止并出现 NSException 类型的未捕获异常”错误。

所以有人知道如何通过按钮选择器将字符串参数传递给另一个方法吗?

最佳答案

如果您使用performSelector 来调用该函数,那么您可以使用此变体

  • (id)performSelector:(SEL)aSelector withObject:(id)对象;

文档

https://developer.apple.com/reference/objectivec/1418956-nsobject/1418764-performselector


您还可以查看这个答案,其中解释了另一个解决方案,在我看来可能更复杂但有用

https://stackoverflow.com/a/14161831/1502070

关于ios - 如何通过按钮选择器将字符串参数传递给另一个方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39630334/

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