0

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.

4

1 回答 1

0

If you are targeting iOS>=6 you can use UICollectionView, they do exactly what you want, and they reuse the cell, to avoid the overhead of recreating vies. They are pretty close to UITableViews. The other solution is find some shared properties or build your own recycling vies mechanism.

于 2013-03-30T09:08:30.397 回答