0
我創建了一個顯示數組productsArray中所有項目的gridView。該數組包含自定義類類型Products的對象。下面顯示的功能是使用來自Products對象的信息創建視圖陣列。現在我想根據父製造商過濾產品。在iOS中重新創建小型UIViews開銷
-(NSArray*)arrayOfObjectToBeAddedToGriView{
NSMutableArray* productsScrolLViewItemsArray = [[NSMutableArray alloc] init];
for (Products* product in productsArray){
ProductScrollViewItem* productScrollViewItem = [[ProductScrollViewItem alloc] initWithFrame:CGRectMake(0,0,0,0) withProduct:product];
[productScrollViewItem addTarget:self action:@selector(productInGridViewTapped:) forControlEvents:UIControlEventTouchUpInside];
[productsScrolLViewItemsArray addObject:productScrollViewItem];
}
return (NSArray*)productsScrolLViewItemsArray;
}
濾波基於廠商
-(void) filterBasedOnManufacturer:(Manufacturer*)selectedManufacturer{
[productsArray removeAllObjects];
[productsArray addObjectsFromArray:[selectedManufacturer.productsForManufacturer allObjects]];
// relod the gridView with filtered products
[productCatalogueGridView reloadItems:[self arrayOfObjectToBeAddedToGriView]];
}
productScrollViewItem是尺寸100,100的與ImageView的和兩個標籤小視圖。我在這裏擔心的是,我每次都重新初始化所有productScrollViewItem,以篩選產品對象。我想知道過濾掉ProductsArray和productScrollViewItemArray是否會更好,或者因爲重新初始化的視圖是非常小的視圖,所以無關緊要。謝謝。