我基本上有一个带有委托协议的 UIView 子类(RRView)。RRViews 通过插座连接到实现委托协议的视图控制器以及委托。
我向代表询问其他信息的代码是这样实现的。
- (void)setDelegate:(id<RRViewDelegate>)delegate {
if (_delegate != delegate) {
_delegate = delegate;
if (_delegate && [_delegate respondsToSelector:@selector(cornersForRRView:)]) {
self.corners = [_delegate cornersForRRView:self];
}
if (_delegate && [_delegate respondsToSelector:@selector(cornerRadiusForRRView:)]) {
CGFloat maxRadius = floorf(self.bounds.size.height/2);
CGFloat radius = [_delegate cornerRadiusForRRView:self];
self.cornerRadius = MIN(radius, maxRadius);
}
if (_delegate && [_delegate respondsToSelector:@selector(rotationTypeForRRView:)]) {
self.type = [_delegate rotationTypeForRRView:self];
}
if (_delegate && [_delegate respondsToSelector:@selector(fontSizeForRRView:)]) {
self.fontSize = [_delegate fontSizeForRRView:self];
self.textFont = [UIFont fontWithName:self.textFont.fontName size:self.fontSize];
}
}
}
我面临的问题是我有一堆 RRView,所以我尝试像这样区分它们,但插座尚未连接。
- (UIRectCorner)cornersForRRView:(RRView *)view {
if ([view isEqual:self.dimensionsInfoView]) {
return UIRectCornerTopLeft | UIRectCornerTopRight;
}
else if ([view isEqual:self.oneHundredPercentInfoView]) {
return UIRectCornerTopRight;
}
else if ([view isEqual:self.deviceApperanceInfoView]) {
return UIRectCornerTopLeft;
}
else {
return 0;
}
}
还有另一种方法可以做到这一点吗?