Im使用字典来保存一些值为“1”的位置;使用NSDictionary碰撞错误 - Iphone SDK
/* * * header * * */
NSDictionary *Mypoints;
/* * * * * * * * */
-(void)myfunc: (float)y :(float)x{
NSLog(@"%@",Mypoints);
NSNumber *one = [NSNumber numberWithInt:1];
NSString *key = [[NSString alloc] initWithFormat:@"%f,%f",y,x];
[Mypoints setObject:one forKey:key];
//show the value
NSNumber *tempNum = [Mypoints objectForKey:key];
int i = tempNum.intValue;
NSLog(@"Value: %i",i);
//print all
NSLog(@"%@",Mypoints);
}
我第一次调用这个函数一切正常,它会创建字典并在最后一行中打印“数组”。但是当我再次输入这个函数时,它会崩溃而没有错误。
我不知道什么可能会发生......
我解决了崩溃做:
Mypoints = [[NSMutableDictionary dictionaryWithObject:one forKey:key]retain];
我解决了如何添加多个点:
//到viewDidLoad中
Mypoints = [[NSMutableDictionary alloc] init];
//进入MYFUNC
[Mypoints setObject:one forKey:key];
然后...我每次输入这个函数时如何添加更多的“积分”? – HispaJavi 2011-01-27 08:39:03