gpt4 book ai didi

ios - 如何正确子类化 UIActionSheet

转载 作者:行者123 更新时间:2023-12-01 19:01:59 26 4
gpt4 key购买 nike

我想要一个子类 UIActionSheet使用 block 方法而不是委托(delegate)。
我的问题是当我在 UIActionSheet 上调用 super 初始化时可变参数 ...在方法结束时不被识别为 va_list并且操作表只显示第一个按钮。

这里类实现.m

@interface FLActionSheet ()
@property (nonatomic,strong) actionClickedBlock clickedBlock;
@end

@implementation FLActionSheet

+ (id)actionSheetWithTitle:(NSString *)title
clickedBlock:(actionClickedBlock)clickedBlock
cancelButtonTitle:(NSString *)cancelButtonTitle
destructiveButtonTitle:(NSString *)destructiveButtonTitle
otherButtonTitles:(NSString *)otherButtonTitles, ...
{
return [[self alloc] initWithTitle:title
clickedBlock:clickedBlock
cancelButtonTitle:cancelButtonTitle
destructiveButtonTitle:destructiveButtonTitle
otherButtonTitles:otherButtonTitles];
}

- (id)initWithTitle:(NSString *)title
clickedBlock:(actionClickedBlock)clickedBlock
cancelButtonTitle:(NSString *)cancelButtonTitle
destructiveButtonTitle:(NSString *)destructiveButtonTitle
otherButtonTitles:(NSString *)otherButtonTitles, ...
{
self = [super initWithTitle:title
delegate:self
cancelButtonTitle:cancelButtonTitle
destructiveButtonTitle:destructiveButtonTitle
otherButtonTitles:otherButtonTitles,nil];

if (self)
{
self.clickedBlock = [clickedBlock copy];
}
return self;
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
self.clickedBlock(buttonIndex);
}

@end

在这里我如何初始化操作表:
[[[FLActionSheet alloc] initWithTitle:@"Ordina per..."
clickedBlock:^(NSInteger buttonIndex) {

switch (buttonIndex)
{
case 0:

break;

default:
break;
}
}
cancelButtonTitle:nil
destructiveButtonTitle:@"Annulla"
otherButtonTitles:@"Data crescente", @"Data decrescente", @"Mittente crescente", @"Mittente decrescente"]
showFromBarButtonItem:myBarButtonItem
animated:YES];

结果如下:

enter image description here

我肯定做错了什么,但我不明白是什么。
想法?

最佳答案

  • UIActionSheet不是 设计为 子类 .
  • 其他方式如何将它与 block 一起使用。最好是创建一个类别 ,实现委托(delegate)协议(protocol)并使用 存储 block 相关项目 机制。 Implementation here.
  • 我认为 initWithTitle:delegate:cancelButtonTitle:...不是 指定初始化器,它是使用 [self init] 实现的有以下 setTitle:addButtonWithTitle:来电。你应该这样做。
  • 事实上,使用可变参数方法,您别无选择。至收集所有论据 , 你必须使用 va_list及相关功能。 Implementation here.然后在他们每个人上调用addButtonWithTitle:如我所说。
  • 关于ios - 如何正确子类化 UIActionSheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22167890/

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