gpt4 book ai didi

ios - 访问单个字符串参数(UIAlertView otherButtonTitles)

转载 作者:行者123 更新时间:2023-11-29 04:12:31 34 4
gpt4 key购买 nike

我正在为应用程序编写自己的自定义警报 View 。客户对警报类型消息有自己的外观/感觉。我读过,子类化 UIAlertView 并不是一个好主意,所以我只是想让我正在使用的当前消息 View 更加动态,这样我就可以更多地重用它.

好的,我的问题。我从 UIAlertView 窃取 init 来初始化我自己的自定义警报。

- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;

这直接取自 Apple 的 UIAlertView 初始值设定项。我的也能正常工作,所以为什么不直接使用他们的 init 呢。

我希望能够为 otherButtonTitles 传递多个字符串,就像 UIAlertView 一样。我的问题是,如何访问传入的字符串?

最佳答案

我可能会将 otherButtonTitles 参数设置为 NSArray 而不是 NSString。从那里,您可以根据数组的计数动态生成其他按钮,并将所述按钮的标题设置为存储在数组当前索引中的 NSString。

编辑:我想我在 UIAlertView.m 中找到了一些有希望的东西(不确定它是否真的来自 Apple),但它也将 otherButtonTitles 作为字符串。它使用 va_list 来存储 otherButtonTitles,然后将对象添加到包含所有按钮的可变数组中,包括索引 0 处的取消按钮(如果适用)。

https://github.com/BigZaphod/Chameleon/blob/master/UIKit/Classes/UIAlertView.m

以下是摘录:

 if (otherButtonTitles) {
[self addButtonWithTitle:otherButtonTitles];

id buttonTitle = nil;
va_list argumentList;
va_start(argumentList, otherButtonTitles);

while ((buttonTitle=(__bridge NSString *)va_arg(argumentList, void *))) {
[self addButtonWithTitle:buttonTitle];
}

va_end(argumentList);
}

关于ios - 访问单个字符串参数(UIAlertView otherButtonTitles),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14199987/

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