MVC: Where can I place a custom UICollectionCell

I am new to development in the mobile world and I have an architectural question for my project:

where is the correct place for the configured UICollectionViewCell?
Instinctively I would place it under V ).

Edit

I would use it this way:

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
  var customCell: CustomCell = collectionView.dequeueReusableCellWithReuseIdentifier(CustomCell.identifier, forIndexPath: indexPath) as! CustomCell
  customCell.setupWithSomeOtherObject(..)
  return customCell;            
}

      

+3


source to share


3 answers


The correct place to put the custom UICollectionViewCell

is your view group, because the cell is there , it will subclass UIView

, so yes, this is the right place for it.



+2


source


To directly answer your question, the UICollectionViewCell must appear in the view.

If you're new to mobile development, I highly recommend learning what the MVVM model is and how you can port it to iOS. The main problem with MVC is that it ultimately ends up in subclasses of ViewController. Also MVVM has advantages when testing your code (yes, in the end you will need that too). Of course, MVVM is not the holy grail, but you can definitely give it a shot.



Good article to start with: MVVM

+1


source


MVC is a great framework for answering your question. But I'll try;

Let's say you're going to create a basic photo gallery.

You need a (M) odel for your objects, let's say it's a photo model and it has a name, createdDate sth. This model simply stores some information in your application.

To display some visual things, the user needs (V) . Like ImageView to show your image like UICollectionView , so UICollectionView is a view. And also UICollectionViewCell is a view inside UICollectionView . Also you can add another view to your cell.

To manage and control this view and model, you need a (C) ondroller. For example, you are storing the path of an image file in a Photo object, now you want to show it in a UICollectionViewCell inside a UICollectionView .

So your UICollectionViewCell answer should be inside your views. In MVC, all controls must be in a Controller to avoid actions inside. You have to provide the delegate with a controller via UICollectionView

+1


source







All Articles