ios - 选择器方法没有被调用

标签 ios objective-c swift drop-down-menu

我正在尝试使用 MKDropDownMenu 库创建一个下拉菜单。我也看到了。但是当点击它时它不会下降并且什么也没有发生。当我深入内心的时候。我发现组件按钮的选择器方法中的按钮没有被调用。

这是声明选择器方法名称的行。

[button addTarget:self action:@selector(selectedComponent:) forControlEvents:UIControlEventTouchUpInside];

下面是实际的方法“selectedComponent”:

- (void)selectedComponent:(MKDropdownMenuComponentButton *)sender {
    if (self.transition.isAnimating) {
        return;
    }
    if (sender == nil) {
        [self closeAllComponentsAnimated:YES];
    } else {
        NSInteger selectedIndex = [self.buttons indexOfObject:sender];
        if (selectedIndex == self.selectedComponent) {
            [self closeAllComponentsAnimated:YES];
        } else {
            [self openComponent:selectedIndex animated:YES];
        }
    }
}

最奇怪的是,这个私有(private)方法在 github 上给出的示例项目中被调用,链接如下:

https://github.com/maxkonovalov/MKDropdownMenu/tree/master/Example

供您引用,我正在使用 swift 并使用 pod 来安装这个库。

任何帮助和建议将不胜感激..

最佳答案

下拉菜单的委托(delegate)和数据源设置了吗?

dropdownMenu.dataSource = self;
dropdownMenu.delegate = self;

关于ios - 选择器方法没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45962821/

相关文章:

ios - 获取用户输入范围时的运行时错误

multithreading - 更改后台线程上 SKSpriteNode 纹理的色调

swift - 以一定的速度在屏幕上移动一个对象。(Sprite Kit)

ios - 如何在放大时在 mkmapview 上显示更多注释并在缩小时显示更少?

objective-c - 我的应用程序在尝试获取包含特殊字符的字符串时崩溃

ios - 添加 UIImagePickerController 作为 subview

iphone - 如何以编程方式转到 UITableView 中的下一个/上一个单元格?

iphone - "Operation couldn' t 完成。连接由对等方重置。”在 iOS 上使用 NSURLConnection

android - Flutter:关闭软键盘后如何保持 TextField 值

objective-c - 自定义表盘时,watchOS 复杂功能未显示为选项