Controller children view UICollectionViewCell

Suppose that I want to get Pinterest contact page, for example:

pinterest

This is my approach:

  • do UICollectionViewController , contact page - UICollectionViewCell
  • cell consists of two components: pin info child vc && & waterfall child vc

Then there is a problem: how can I re-use the controller of children's presentation?

Some pseudo-code:

 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; Pin *pin = self.dataSource[indexPath.row]; // i have to create a new childVC, based on different indexPath. UITableViewController *pinInfoViewController = [[pinInfoViewController alloc] initWithPin:pin]; [cell updatePinViewWithPin:pin]; [self addChildViewController:pinInfoViewController]; // Add waterfall view controller } ; - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; Pin *pin = self.dataSource[indexPath.row]; // i have to create a new childVC, based on different indexPath. UITableViewController *pinInfoViewController = [[pinInfoViewController alloc] initWithPin:pin]; [cell updatePinViewWithPin:pin]; [self addChildViewController:pinInfoViewController]; // Add waterfall view controller } , based on different indexPath. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; Pin *pin = self.dataSource[indexPath.row]; // i have to create a new childVC, based on different indexPath. UITableViewController *pinInfoViewController = [[pinInfoViewController alloc] initWithPin:pin]; [cell updatePinViewWithPin:pin]; [self addChildViewController:pinInfoViewController]; // Add waterfall view controller } ] initWithPin: pin]; - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; Pin *pin = self.dataSource[indexPath.row]; // i have to create a new childVC, based on different indexPath. UITableViewController *pinInfoViewController = [[pinInfoViewController alloc] initWithPin:pin]; [cell updatePinViewWithPin:pin]; [self addChildViewController:pinInfoViewController]; // Add waterfall view controller } 

Each time this method is called, the new controller is the child view is created, it is normal or how to improve it?

+6
source share
3 answers

The way I would have approached this refers to a subclass UICollectionViewCell and adds user interface components that you need for it as iVars. When you need to update the user interface with new data, you have captured the cell object as now, in pseudo-code, and then call the method that you declare, can be updateCellWithModel: and give him a model, which is stored in the data source. In this method, you will spend a few simple checks if the user interface elements are created or not, and create them, if necessary, is always a good idea to have a health check in these types of methods, but the items must be created in the init method and will always be there.

EDIT: I think the answer to your question, but it still confuses me, add more information that I could edit my response, if necessary.

+1
source

I recently encountered a similar situation and fought for choice between different solutions, such as the details described in UIViewController in UICollectionView . It seems that there is an open source project, which now encapsulates this template: https://github.com/zats/Voltron . If your problem can be solved with the help of UICollectionView UIViewControllers, then it will be easier to accomplish than trying to roll your own.

+2
source

I do not think they use a collection view of the table cell with built-in performance here. He looks like a normal controller viewing, which is for the pins. Data pulled out from the server to said probe are likely to contain information about the pin name, a link to a contact, image, all the people who added the pin, who was the original friend, likes, favorites, and so on, and view controller analyzes this data accordingly. The controller uses this information to update the user interface, and this.

I see a representation of a table and a collection that Pinterest could be used to implement this view controller, but it does not seem that they have built all these data into a cell collection.

0
source

All Articles