Ứng dụng của tôi bị lỗi sau khi tôi gọi hàm addImageToQueue. Tôi đã thêm initWithObjects: forKeys: count: nhưng nó không giúp tôi.NSDictionary: phương thức chỉ được định nghĩa cho lớp trừu tượng. Ứng dụng của tôi bị lỗi
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '*** -[NSDictionary initWithObjects:forKeys:count:]:
method only defined for abstract class.
Define -[DictionaryWithTag initWithObjects:forKeys:count:]!'
mã của tôi
- (void)addImageToQueue:(NSDictionary *)dict
{
DictionaryWithTag *dictTag = [DictionaryWithTag dictionaryWithDictionary:dict];
}
@interface DictionaryWithTag : NSDictionary
@property (nonatomic, assign) int tag;
- (id)initWithObjects:(id *)objects forKeys:(id *)keys count:(NSUInteger)count;
@end
@implementation DictionaryWithTag
@synthesize tag;
- (id)initWithObjects:(id *)objects forKeys:(id *)keys count:(NSUInteger)count
{
return [super initWithObjects:objects forKeys:keys count:count];
}
@end
Bạn không nên phân lớp NSDictionary. Tại sao bạn làm việc đó ? – giorashc
Tôi muốn thêm thuộc tính thẻ. Đó là tính năng tuyệt vời. Có thể tôi cần phải thêm khóa mới vào một từ điển và không phân lớp NSDictionary. – Voloda2