如何将swift选择器引用发送到目标c属性



我在目标C类中有属性@property (nonatomic, assign) SEL buttonSelector,它有显示的按钮

- (void)setUpBarButton:(id)vc {
    UIBarButtonItem * optionsItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Options"] style:UIBarButtonItemStylePlain target:vc action:buttonSelector];
    optionsBarItem.imageInsets = UIEdgeInsetsMake(0.0, 2.0, 0.0, 2.0);
    self.navigationItem.rightBarButtonItems = @[self.optionsItem];
}

所以从swift类,我使用上面的方法,所以我必须发送来自swift类的选择器引用

self.buttonSelector= #selector(tapbutton:)

但它给出了一个错误

您的代码太bug了。有三个按钮变量:

optionsItem
self.optionsItem
optionsBarItem 

为什么还要有一个选择器变量?只需在选择器中处理任何不同的情况!

最新更新