我有一个班级办公室供应
@interface OfficeSupply : NSObject
@property (nonatomic, strong) NSString *itemName;
@property (nonatomic) int total;
@property (nonatomic) int price;
@property (nonatomic) int quantity;
@property (nonatomic, strong) UITextField *quantityText;
@property (nonatomic, strong) UIImage *itemPic;
-(id)initWithName:(NSString *)itemName total:(int)total price:(int)price quantity:(int)quantity picture:(UIImage *)itemPic;
@end
在我看来,我有
OfficeSupply *item1 = [[OfficeSupply alloc] initWithName:@"Stapler" total:0 price:50 quantity:0 picture:[UIImage imageNamed:@"stapler.jpg"]];
OfficeSupply *item2 = [[OfficeSupply alloc] initWithName:@"Paper" total:0 price:150 quantity:0 picture:[UIImage imageNamed:@"101291.jpg"]];
OfficeSupply *item3 = [[OfficeSupply alloc] initWithName:@"Pen" total:0 price:45 quantity:0 picture:[UIImage imageNamed:@"pen.jpg"]];
_items =[NSArray arrayWithObjects:item1, item2, item3, nil];
[_items sortedArrayUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"itemName" ascending:YES selector:@selector(caseInsensitiveCompare:)]]];
我已经查找了问题,但无法解决我的问题。
最后一行应该对其进行排序,但我不知道为什么它不会。
我只想按名称对它们进行排序..有什么想法吗?