继承类的调用方法

继承类的调用方法

我有两个班级A和B。在班级A中,我使用:

@interface A : B


在B类中,我有以下代码行:

self.navigationItem.rightBarButtonItem = [UIBarButtonItem barItemWithImage:[UIImage imageNamed:@"Add-button-normal"]
                                                          highlightedImage:[UIImage imageNamed:@"Add-button-active"]
                                                                    target:self
                                                                    action:@selector(showPopoverUI:)];


我如何在A类中访问此项目,我尝试了以下代码行,但它不起作用:

self.navigationItem.rightBarButtonItem = [UIBarButtonItem barItemWithImage:[UIImage imageNamed:@"Add-button-normal"]
                                                          highlightedImage:[UIImage imageNamed:@"Add-button-active"]
                                                                    target:self.parentViewController
                                                                    action:@selector(showPopoverUI:)];


我得到了这个错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[B showPopoverUI:]: unrecognized selector sent to class 0x226308'

最佳答案

在第二个示例中,您将目标定位为parentViewController,而应继续以self为目标。

关于iphone - 继承类的调用方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14464284/

10-10 00:31