我正在将BEMSimpleLineGraph库集成到我的Objective-C iPhone应用程序中,并且在将核心数据中的int值添加到NSMutableArray中,以及稍后在同一个类中检索不同方法中的值时遇到了问题。
下面是我用来填充数组的代码:
// Get those points from Core Data into my arrays
for (int i = 0; i < countInArray; i++) {
NSManagedObject *device = [self.tapTestsConducted objectAtIndex:i];
int leftInt, rightInt;
leftInt = [[device valueForKey:@"leftNumber"] intValue];
rightInt = [[device valueForKey:@"rightNumber"] intValue];
[_leftArray addObject: [NSNumber numberWithInt:leftInt]];
[_rightArray addObject: [NSNumber numberWithInt:rightInt]];
NSDate *date = [device valueForKey:@"date"];
[self.dateArray addObject: date];
// For testing - Did the correct data get into the arrays?
NSLog(@"%d", leftInt);
NSLog(@"%d", rightInt);
NSLog(@"%@", date);
}下面是用于查找图形的y值的方法:
- (CGFloat)lineGraph:(BEMSimpleLineGraphView *)graph valueForPointAtIndex:(NSInteger)index {
NSNumber *anumber = [_leftArray objectAtIndex:index];
int anInt = [anumber intValue];
NSLog(@"%d", anInt);
return anInt;
}第一部分中的NSLog输出正确的数据,但第二个方法中的NSLog输出全0。
任何建议或意见都是非常感谢的!
编辑:以下是运行时的NSLog输出:
2016-09-11 22:30:04.072 CNS Test CD[16805:849994] 5 tests conducted
2016-09-11 22:30:04.072 CNS Test CD[16805:849994] 12
2016-09-11 22:30:04.072 CNS Test CD[16805:849994] 0
2016-09-11 22:30:04.072 CNS Test CD[16805:849994] 2016-08-31 23:49:12 +0000
2016-09-11 22:30:04.072 CNS Test CD[16805:849994] 20
2016-09-11 22:30:04.072 CNS Test CD[16805:849994] 0
2016-09-11 22:30:04.072 CNS Test CD[16805:849994] 2016-09-02 23:31:44 +0000
2016-09-11 22:30:04.073 CNS Test CD[16805:849994] 0
2016-09-11 22:30:04.073 CNS Test CD[16805:849994] 17
2016-09-11 22:30:04.073 CNS Test CD[16805:849994] 2016-09-02 23:32:12 +0000
2016-09-11 22:30:04.073 CNS Test CD[16805:849994] 12
2016-09-11 22:30:04.073 CNS Test CD[16805:849994] 0
2016-09-11 22:30:04.073 CNS Test CD[16805:849994] 2016-09-05 19:13:19 +0000
2016-09-11 22:30:04.073 CNS Test CD[16805:849994] 13
2016-09-11 22:30:04.073 CNS Test CD[16805:849994] 0
2016-09-11 22:30:04.074 CNS Test CD[16805:849994] 2016-09-05 19:13:55 +0000
2016-09-11 22:30:05.949 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.950 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.950 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.950 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.950 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.950 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.950 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.950 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.950 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.951 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.955 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.955 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.955 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.956 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.956 CNS Test CD[16805:849994] 0发布于 2016-09-13 10:20:44
我在.h文件中正确地声明了我的NSMutableArrays:
@property (strong, nonatomic) NSMutableArray *leftArray;
@property (strong, nonatomic) NSMutableArray *rightArray;
@property (strong, nonatomic) NSMutableArray *dateArray;我没有做的,并且在我做了之后修复了这个问题,是用一个分配初始化来初始化我的arras。我将这些行放在for循环之前。
self.leftArray = [[NSMutableArray alloc] init];
self.rightArray = [[NSMutableArray alloc] init];
self.dateArray = [[NSMutableArray alloc] init];https://stackoverflow.com/questions/39443991
复制相似问题