在 mouseDown 和 mouseDragged 处:
locll = [self convertPoint: [event locationInWindow] fromView:nil];
NSValue *locationValuell = [NSValue valueWithPoint:locll];
[vertices addObject:locationValuell];
在 mouseUp
NSString *index = [NSString stringWithFormat:@"%d", aIndex++];
[aDict setObject:vertices forKey:index];
NSArray *allKeys = [aDict allKeys];
NSLog(@"dict count: %ld", [allKeys count]);
NSString *index1 = [NSString stringWithFormat:@"%d", aIndex];
NSMutableArray *a = [aDict objectForKey:index1];
NSLog(@"a count:%li", [a count]);
在 initWithCoder
int aIndex = 0;
dict count 返回有多少对象存储在字典中。它有效。但是后来当我尝试从字典中取回数组时,我检查了数组中有多少对象([a count])并且它返回 0。所以我猜 NSMutableDictionary 清空了我的 NSMutableArray,或者我以错误的方式取回它。