gpt4 book ai didi

iphone - 如何在iPhone中的UIActionSheet中动态添加按钮

转载 作者:行者123 更新时间:2023-12-03 19:06:08 25 4
gpt4 key购买 nike

我需要在 iPhone 的 UIActionSheet 中动态添加按钮。请帮助我。

最佳答案

只需分配并初始化一个新的 UIActionSheet 实例,然后使用 –addButtonWithTitle: 逐个添加按钮。此方法返回按钮已添加到的索引。然后,您可以通过 -setDestructiveButtonIndex 设置破坏性按钮的索引。

下面是一个示例,如果 bool 值 useDestructiveButtonYES,则添加一个按钮并添加另一个按钮(并直接将其设置为破坏性按钮,使其变为红色):

UIActionSheet *sheet = [[UIActionSheet alloc] init];
[sheet addButtonWithTitle:@"Button 1"];
if (useDestructiveButton) {
[sheet setDestructiveButtonIndex:[sheet addButtonWithTitle:@"Button 2"]];
}

不要忘记调用适当的显示方法。

关于iphone - 如何在iPhone中的UIActionSheet中动态添加按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4782790/

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