我對這些委託方法調用感到困惑。下面的委託方法調用有什麼區別?
哪一個是調用委託方法的正確方法?
@protocol XYZDelegate <NSObject>
@required
- (void)someMethod:(id)someObject;
@end
方法1:
- (void)someButtonAction:(UIButton *)sender {
if([self.delegate && [self.delegate respondsToSelector:@selector(someMethod:)]]) {
[self.delegate someMethod:sender];
}
}
方法2:
- (void)someButtonAction:(UIButton *)sender {
if([self.delegate && [self.delegate respondsToSelector:@selector(someMethod:)]]) {
[self.delegate performSelector:@selector(someMethod:) withObject:sender];
}
}
格式。請。 – Avi
CMD K是如何修復格式。不是空格鍵或刪除按鈕。 – Fogmeister
@Fogmeister,感謝格式化提示 – HPM