相关疑难解决方法(0)

使用NSArray指定otherButtonTitles?

UIAlertSheet的构造函数将otherButtonTitles参数作为varg列表.我想指定NSArray中的其他按钮标题.这可能吗?

即我必须这样做:

id alert = [[UIActionSheet alloc] initWithTitle: titleString
                                  delegate: self
                                  cancelButtonTitle: cancelString
                                  destructiveButtonTitle: nil
                                  otherButtonTitles: button1Title, button2Title, nil];
Run Code Online (Sandbox Code Playgroud)

但由于我在运行时生成可用按钮列表,我真的想要这样的东西:

id alert = [[UIActionSheet alloc] initWithTitle: titleString
                                       delegate: self
                              cancelButtonTitle: cancelString
                         destructiveButtonTitle: nil
                              otherButtonTitles: otherButtonTitles];
Run Code Online (Sandbox Code Playgroud)

现在,我想我需要单独拨打一个initWithTitle:项目,2个项目和3个项目.像这样:

if ( [titles count] == 1 ) {
     alert = [[UIActionSheet alloc] initWithTitle: titleString
                                         delegate: self
                                cancelButtonTitle: cancelString
                           destructiveButtonTitle: nil
                                otherButtonTitles: [titles objectAtIndex: 0], nil];
} else if ( [titles count] == 2) {
     alert = [[UIActionSheet alloc] initWithTitle: titleString
                                         delegate: self …
Run Code Online (Sandbox Code Playgroud)

iphone nsarray uialertsheet

54
推荐指数
3
解决办法
2万
查看次数

标签 统计

iphone ×1

nsarray ×1

uialertsheet ×1