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

标签 objective-c c function parameters arguments

例如,这是我的 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/

相关文章:

c++ - 我可以从 C 调用 std::function 吗?

objective-c - 没有子类化 UIView 或 UIViewController : possible to catch if a subview was added?

iOS 应用程序不会在 iPhone 上旋转,但会在 iPad 上旋转

ios - 从 Bundle 加载图像我得到一个 nil

C fscanf 输入验证

c - 增加固定间隔的数量

javascript - 在另一个 React 组件函数中调用 React 组件函数?

c# - 夜间检查功能 c#

postgresql - 在 PostgreSQL 中授予执行函数 pg_start_backup 不起作用

c++ - "assignment of read-only variable"