有条件地传递变量参数

spd*_*spd 0 iphone macos conditional objective-c variadic-functions

在我的一个iPhone应用程序中,我需要有条件地将变量参数发送到操作表.即

if(condition1)
    otherButtonTitles = @"Button1", @"Button2", nil
else
    otherButtonTitles = @"Button3", @"Button4", nil

UIActionSheet *mediaActionsSheet = [[UIActionSheet alloc] initWithTitle: nil
                                                             delegate: self
                                                    cancelButtonTitle: @"Cancel"
                                               destructiveButtonTitle: nil
                                                    otherButtonTitles: otherButtonTitles];
Run Code Online (Sandbox Code Playgroud)

这样做的语法是什么?应如何定义otherButtonTitles的数据类型?

提前致谢.

此致,Deepa

小智 7

UIActionSheet * mediaActionsSheet;
mediaActionSheet = [[UIActionSheet alloc] initWithTitle: nil
                                               delegate: self
                                      cancelButtonTitle: @"Cancel"
                                 destructiveButtonTitle: nil
                                      otherButtonTitles:nil];


if(condition1){

    [mediaActionsSheet addButtonWithTitle:@"Button1"];
    [mediaActionsSheet addButtonWithTitle:@"Button2"];
}
else {

    [mediaActionsSheet addButtonWithTitle:@"Button3"];
    [mediaActionsSheet addButtonWithTitle:@"Button4"];
}
Run Code Online (Sandbox Code Playgroud)