我正在将BEMSimpleLineGraph库集成到我的Objective-C iPhone应用程序中,我在将Core数据中的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
答案 0 :(得分:0)
我已经在我的.h文件中正确声明了我的NSMutableArrays:
@property (strong, nonatomic) NSMutableArray *leftArray;
@property (strong, nonatomic) NSMutableArray *rightArray;
@property (strong, nonatomic) NSMutableArray *dateArray;
我没做过,在我做完之后修复了问题,就是用alloc init初始化我的arras。我把这些行放在for循环之前。
self.leftArray = [[NSMutableArray alloc] init];
self.rightArray = [[NSMutableArray alloc] init];
self.dateArray = [[NSMutableArray alloc] init];