有兩個類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'
在第二個例子中你target了parentViewController
,應該繼續target self。