Reputation: 37
I have been looking out to learn about collection view in this link for a days. In this link it has viewcontroller.h,.m
and also CustomCollectionCell.h,.m
.
Why are they creating separate class for that cell? We can use the viewcontroller.m
file to manage our cell
in collection view.
how ARC works (retain cycles, weak vs. strong, etc), threading (when to use background thread, when to use main).
Upvotes: 0
Views: 62
Reputation: 4111
1.Why are they creating separate class for that cell.we can use the viewcontroller.m file to manage our cell in collection view.
Ans:Relating to real life, why we have separate rooms for study, drawing room, bedroom etc. Each and every thing has it's own scope. You can keep all your code in one file but for the shake of code reusability, moduled, in scope they have created seperated classes.
2.how ARC works (retain cycles, weak vs. strong, etc), threading (when to use background thread, when to use main).
Ans: Arc basically help automatically to manage memory.Thus saving development time. Retain Cycle: If two objects are holding each other strongly then none of them release to each other.Example:
Think about this setUp You have a property as
@property(nonatomic, strong)AViewControllerObj *aViewControllerObj;
@property(nonatomic, strong)NSString *nameString;
then somewhere in your code you write
aViewControllerObj.nameString = self.nameString;
nameString
property in aViewControllerObj
is also strong
.
So here in this case you are creating two properties both with strong
, so it will create a retain cycle.
To solve it change
nameString
property in aViewControllerObj
is to weak
.
MainThread vs BackgroundThread: Do all UIStuff in main thread. You can schedule non-ui stuff in background thread.
You can see some of more helpful points here in my answer: helpful memory related points
Hope it helps you
Upvotes: 1
Reputation: 509
Hi This is matter of choice to create separate class for collection View cell , you can also create the custom collection view cell class in .m file
dequeueReusableCellWithReuseIdentifier:simpleTableIdentifier forIndexPath is method of UICollectionView same as in UITableView this methods just reuse the cells that are created, by this compile don't need to create a cell each time when you scroll or update data in collection view , this enable us to reuse the collectionView Cell.
Upvotes: 0