(1)第一步设置一下button
    IBOutlet NSButton * nameOrderBT;
IBOutlet NSButton * sizeOrderBT;
(2)切换设置切换相遇函数
-(IBAction) nameOrderAction:(id)sender
{ [sizeOrderBT setTitle:@"Width"];
if ([nameOrderBT.title isEqualToString:@"Name⬆️"])
{
[nameOrderBT setTitle:@"Name⬇️"]; _itemOrder=RFICONMODEL_ORDER_FILENAME_DESC; }
else{
[nameOrderBT setTitle:@"Name⬆️"];
_itemOrder=RFICONMODEL_ORDER_FILENAME_ASC;
}
[self updateTable];
return; }
-(IBAction) sizeOrderAction:(id)sender
{
[nameOrderBT setTitle:@"Name"];
if ([sizeOrderBT.title isEqualToString:@"Width⬆️"])
{
[sizeOrderBT setTitle:@"Width⬇️"];
_itemOrder=RFICONMODEL_ORDER_IMAGEWIDTH_DESC;
}
else{
[sizeOrderBT setTitle:@"Width⬆️"];
_itemOrder=RFICONMODEL_ORDER_IMAGEWIDTH_ASC;
}
[self updateTable];
return; }

(3)设置item获取顺序

{
if (_itemOrder==nil) {
_itemOrder=@""; }
return _itemOrder;
} -(NSMutableArray*) getItemsArray
{
if (itemsArray==nil) {
itemsArray=[NSMutableArray array];
//NSArray * modelArray=[RFIConModel getItemByGroupName:[self getGroupNameBySafe]];
NSArray * modelArray=[RFIConModel getItemByGroupName:[self getGroupNameBySafe] order:[self getItemOrderBySafe]];
for (RFIConModel * model in modelArray) {
ItemPreCellVC * oneVC=[[ItemPreCellVC alloc] init];
oneVC.itemModel=model;
[itemsArray addObject:oneVC];
}
}
return itemsArray;
}
其中[RFIConModel getItemByGroupName:[self getGroupNameBySafe] order:[self getItemOrderBySafe]]是order关键,这样只需设施一下itemOrder,就可自动更新内容了。
05-11 15:18