I have created a gridView that is showing all items in an array productsArray. This array hold the objects of a custom class type ,Products. The below shown function is creating an Array of views using the information from a Products object.Now I want to filter the Products based on the parent Manufacturer.
-(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;
}
Filtering based on Manufacturer
-(void) filterBasedOnManufacturer:(Manufacturer*)selectedManufacturer{
[productsArray removeAllObjects];
[productsArray addObjectsFromArray:[selectedManufacturer.productsForManufacturer allObjects]];
// relod the gridView with filtered products
[productCatalogueGridView reloadItems:[self arrayOfObjectToBeAddedToGriView]];
}
productScrollViewItem is a small view of size 100,100 with an ImageView and two labels. My concern here is that I am re-initializing all the productScrollViewItem every time for the filtered Products Objects. I am wondering if it would be better to filter out both the ProductsArray and the productScrollViewItemArray or it does not matter since the views I am reinitializing are very small views. Thanks.