iPhone SDK - UIActionSheet - 动态按钮标题 [英] iPhone SDK - UIActionSheet - Dynamic Button Titles

查看:78
本文介绍了iPhone SDK - UIActionSheet - 动态按钮标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中有一个要求,我需要能够动态添加otherButtonTitles,这取决于用户在设置中指定的一些BOOL开关。但是,我似乎无法弄清楚如何在UIActionSheet初始化中执行此操作。我试图传递一个NSString数组(NSString [2]),也没有运气的NSArray。

I have a requirement in an application where I need to be able to add otherButtonTitles dynamically, dependent upon some BOOL switches that a user has specified in the settings. However, I can't seem to figure out how to go about doing this in the UIActionSheet initialization. I've tried to pass a NSString array (NSString[2]), and also a NSArray without any luck.

非常感谢任何帮助。

推荐答案

我找到的最简单的方法是创建没有按钮的操作表,包括没有取消或破坏性按钮:

The easiest way to do this that I have found is initially create your action sheet with no buttons, including no cancel or destructive button:

UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@"Dynamic"
                                                        delegate:self
                                               cancelButtonTitle:nil
                                          destructiveButtonTitle:nil
                                               otherButtonTitles:nil];

然后根据需要添加一些按钮:

Then add a load of buttons as needed:

if(buttonX)
{
    [actionSheet addButtonWithTitle:@"Button X"];
}
if(buttonY)
{
    [actionSheet addButtonWithTitle:@"Button Y"];
}
if(buttonZ)
{
    [actionSheet addButtonWithTitle:@"Button Z"];
}

然后最后在结尾添加取消按钮并设置取消按钮索引:

Then finally add the cancel button at the end and set the cancel button index:

[actionSheet addButtonWithTitle:@"Cancel"];
actionSheet.cancelButtonIndex = actionSheet.numberOfButtons - 1;

当然,你可以用这种方式添加取消按钮和/或破坏性按钮。

Of course you can add both a cancel button and/or a destructive button in this way.

这篇关于iPhone SDK - UIActionSheet - 动态按钮标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆