我正在尝试将 NSNumber 放入数组中:
NSNumber *n = [NSNumber numberWithInt:1];
[[array objectAtIndex:0] setValue:n forKey:@"1"];
然后我有一个 Action ,我希望它从数组中打印 n.intValue。我是这样写的:
-(IBAction)action:(id)sender {
NSNumber *n = [[array objectAtIndex:0 ] valueForKey:@"1"];
NSLog(@"%d",n.intValue);
}
问题是它打印的是 0 而不是 1。
我怎样才能重写它以使其工作?
谢谢。
最佳答案
你可以简单地这样做
NSMutableArray *array=[[NSMutableArray alloc] init];
NSNumber *n = [NSNumber numberWithInt:1];
[array addObject:n];
NSLog(@"%@",[array objectAtIndex:0 ]);
关于ios - 如何从数组中读取 NSNumber?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9715314/