我使用以下方法创建一个NSMutableArray并向其中添加一些值:
NSMutableArray * pointsForInterpolation = [[NSMutableArray alloc] init];
//Code to add objects to array 然后,我通过在分配和初始化数组的相同方法中执行以下操作,设置了一个与数组相等的属性:
self.wavePoints = pointsForInterpolation;self.wavePoints是一个NSMutableArray属性,它很强(@property(nonatomic,strong) NSMutableArray *wavePoints;)。然后,我执行以下操作:
-(void) setWavePoints:(NSMutableArray *)wavePoints
{
_wavePoints = wavePoints;
NSLog(@"_wavePoints count %lu", [_wavePoints count]);
}我的NSLog显示_wavePoints有一个有效的计数,并且不是nil。我继续执行其他一些与数组无关的方法,直到我到达最后一个方法:
- (UIBezierPath*) createPath
{
NSLog(@"Wave points count %lu", [_wavePoints count]);
NSMutableArray* data = [self.wavePoints mutableCopy];
NSLog(@"ARRay count 2 %lu", [data count]);
}标题:
@interface OSWaveView ()
@property(nonatomic,strong)AVAsset *audioAsset;
@property(nonatomic,strong) NSMutableArray *wavePoints;
@property (nonatomic, strong) NSMutableArray * pointsForInterpolation;
@property(nonatomic,assign)CGFloat minAmpl;
@property(nonatomic,assign)CGFloat maxAmpl;
@property (nonatomic, strong) CAShapeLayer* blueWave;
@property (nonatomic, strong) CAShapeLayer* redWave;
@end最后两个NSLog显示的计数为零。我的初始数组(pointsForInterpolation)发布了吗?
发布于 2014-07-22 14:12:25
-(void) setWavePoints:(NSMutableArray *)wavePoints {
_wavePoints = wavePoints;
NSLog(@"_wavePoints count %lu", [_wavePoints count]);
}
My NSLog shows that _wavePoints has a valid count and is not nil. I go on to execute some other methods that have nothing to do with the array until I reach this last method:
- (UIBezierPath*) createPath
{
NSLog(@"Wave points count %lu", [_wavePoints count]);
NSMutableArray* data = [self.wavePoints mutableCopy];
NSLog(@"ARRay count 2 %lu", [data count]);
}你的解释有点偏差。即使_wavePoints为零,您的日志也会返回0。您应该进行显式检查,以查看数组是否为nil。
如果NSLog(@"%@", self.wavePoints)被正确初始化,它应该返回nil/零以外的值。一旦确认了这一点,您就知道数组不是问题所在,而是没有向数组添加任何值,这会将问题指向for循环,并且与要置零的数组没有任何关系。
https://stackoverflow.com/questions/24877727
复制相似问题