是否可以将变量重新声明为不同的类型?

时间:2013-06-07 05:16:26

标签: objective-c

@protocol BGTableViewDelegateMother <BGIhaveNavigationController>



@end

@interface BGTableViewDelegateMother : NSObject
@property (weak,nonatomic) UITableView * tv;
@property id <BGIhaveNavigationController> delegate;
@end

说后者我想继承BGTableViewDelegateMother。

但是,我想将委托的类型更改为其他内容。也许不是。有可能吗?

当然BGIhaveNavigationControllerandsomeotherthing继承自BGIhaveNavigationController

1 个答案:

答案 0 :(得分:1)

只要您的子类委托符合的协议包含BGIhaveNavigationController协议,它就没问题。你可以这样做:

@protocol BGIhaveNavigationControllerAndSomethingElse <BGIhaveNavigationController>
- (void)somethingElse;
@end

@interface BGTableViewDelegateChild : BGTableViewDelegateMother
@property id <BGIhaveNavigationControllerAndSomethingElse> delegate;
@end

请注意,如果BGIhaveNavigationControllerAndSomethingElse被声明为

@protocol BGIhaveNavigationControllerAndSomethingElse <NSObject>

(即不包含BGIhaveNavigationController)然后编译器会抱怨BGIhaveNavigationController的委托类型。