gpt4 book ai didi

objective-c - 如何访问 C 函数中的 N 个参数并将相同的 N 传递给下一个?

转载 作者:行者123 更新时间:2023-11-30 14:27:01 25 4
gpt4 key购买 nike

例如,这是我的 C(和 Objective-C)方法,如下所示。

void ALERT(NSString *title, NSString *message,NSString *canceBtnTitle,id delegate,NSString *otherButtonTitles, ... )
{
// HERE I CAN ACCESS ALL THOSE ARGUMENTS
// BUT I AM NOT SURE How to access additional arguments, supplied using ... ?

UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:title
message:message
delegate:delegate
cancelButtonTitle:canceBtnTitle
otherButtonTitles:// how to pass those params here?];
}

正如您所注意到的,我还必须在 UIAlertViewinit 方法中传递这些参数。我不确定如何将这些参数发送到 otherButtonTitles 中。我可以通过以下方式调用这个方法。

ALERT(@"My Alert Title",@"Alert Subtitle",@"YES",viewCtr,@"No",@"May Be",@"Cancel",nil);

ALERT(@"Alert Title",@"Alert Subtitle",@"OK",viewCtr,@"Cancel",nil);

ALERT(@"Alert Title",@"Alert Subtitle",@"OK",viewCtr,nil);

ALERT(@"Alert Title",@"Alert Subtitle",@"OK",viewCtr,@"Option1",@"Option2",nil);

最佳答案

听起来您需要了解 va_arg(以及 va_list、va_start、va_end)。

Here's a tutorial on the subject .

此外,a fine Apple tech note entitled "How can I write a method that takes a variable number of arguments, like NSString's +stringWithFormat:?"

编辑添加:

听起来你想做va_copy

啊,here is a related question .

关于objective-c - 如何访问 C 函数中的 N 个参数并将相同的 N 传递给下一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8266638/

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