我认为这是100%直截了当而且我感觉比有点哑成立现在。我有一个带有公共财产的NSObject
基础班NORPlayer
:
@property (nonatomic, strong) NSArray *pointRollers;
但是,这不是子类继承的。数组是这样设置的,它可以正常工作:
家长班:
@implementation NORPlayer
- (instancetype)init{
self = [super init];
if (self) {
[self setup];
}
return self;
}
- (void)setup{
NSMutableArray *tempRollersArray = [[NSMutableArray alloc] init];
for (NSUInteger counter = 0; counter < 5; counter++) {
NORPointRoller *aRoller = [[NORPointRoller alloc] init];
[tempRollersArray addObject:aRoller];
}
_pointRollers = [NSArray arrayWithArray:tempRollersArray];
}
当试图从创建一个子类NORPlayer
来NORVirtualPlayer
然而事情就会出差错:
子类:
#import "NORPlayer.h"
@interface NORVirtualPlayer : NORPlayer
// none of the below properties nor the method pertains to the problem at hand
@property (nonatomic, assign) NSArray *minimumAcceptedValuePerRound;
@property (nonatomic, assign) NSUInteger scoreGoal;
@property (nonatomic, assign) NSUInteger acceptedValueAdditionWhenScoreGoalReached;
- (void)performMoves;
@end
的初始化NORVirtualPlayer
是通过调用setup方法的init方法镜像其父类:
@implementation NORVirtualPlayer
- (instancetype)init{
self = [super init];
if (self) {
[self setup];
}
return self;
}
- (void)setup{
self.minimumAcceptedValuePerRound = @[ @5, @5, @5, @5, @5 ];
self.scoreGoal = 25;
self.acceptedValueAdditionWhenScoreGoalReached = 0;
}
问题在于NORVirtualPlayer
实例永远不会获得启动pointRollers
属性。我已经完成了所有步骤,并在parentClass和子类中调用了setup方法。
感觉上这肯定是一个相当基本的问题,但是我无法解决这个问题。任何帮助将不胜感激。干杯!
解决方案:如下所述。令人尴尬,但仍然开心。首先到达Putz1103真的很荣幸。我认为超级的设置将通过其初始化方法调用,但并不是很明显...
我看不到从NORVirtualPlayer调用您的NORPlayer的设置,这是初始化数组的地方。
- (void)setup{
self.minimumAcceptedValuePerRound = @[ @5, @5, @5, @5, @5 ];
self.scoreGoal = 25;
self.acceptedValueAdditionWhenScoreGoalReached = 0;
}
您是否也要调用超级设备的设置?
- (void)setup{
[super setup];
self.minimumAcceptedValuePerRound = @[ @5, @5, @5, @5, @5 ];
self.scoreGoal = 25;
self.acceptedValueAdditionWhenScoreGoalReached = 0;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句