Make a collection controller to several components. A UICollectionView/UITableView
framework for building fast and flexible lists. Like IGList
.
- Xcode 8.0+
- iOS 8.0+
pod 'DDComponent', :git => 'https://github.com/liuxc123/DDComponent.git', :tag => '1.0.11'
The implementation code of this component adopts djs66256/DDComponent
For easy using, the api is similar to UICollectionView
and UITableView
.
@interface YourComponent : DDCollectionViewSectionComponent
@end
@implementation
- (instancetype)init
{
self = [super init];
if (self) {
self.size = CGSizeMake(DDComponentAutomaticDimension, 44);
// config here.
// Remember self.collectionView is nil until it is added to root component.
}
return self;
}
- (void)prepareCollectionView {
[super prepareCollectionView];
// register your cell here.
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 1;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return ... // Return your cell
}
@end
And the other api is also the same.
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
// select item
}
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
// will display
}
po self.rootComponent
<DDCollectionViewRootComponent: 0x6080000bb900>
[SubComponents]
<DDComponentPodDemo.StatusComponent: 0x60800009b440>
-[loading] <DDComponentPodDemo.StateComponent: 0x6080001651c0>
*[normal] <DDCollectionViewSectionGroupComponent: 0x60800009acc0>
[SubComponents]
<DDComponentPodDemo.TaobaoBannerComponent: 0x6080001235c0>
<DDComponentPodDemo.TaobaoEntriesComponent: 0x6080001524e0>
<DDComponentPodDemo.TaobaoGoodsComponent: 0x608000151eb0>
<DDComponentPodDemo.TaobaoGoodsComponent: 0x608000151510>
[Header] <DDComponentPodDemo.HeaderComponent: 0x608000151250>
<DDComponentPodDemo.TaobaoGoodsComponent: 0x608000152220>
<DDComponentPodDemo.TaobaoGoodsComponent: 0x608000152380>
<DDComponentPodDemo.TaobaoGoodsComponent: 0x6080001511a0>
<DDComponentPodDemo.TaobaoGoodsComponent: 0x608000151b40>
[Header] <DDComponentPodDemo.HeaderComponent: 0x608000151ca0>
<DDComponentPodDemo.TaobaoGoodsComponent: 0x608000152170>
<DDComponentPodDemo.TaobaoGoodsComponent: 0x6080001515c0>
<DDComponentPodDemo.TaobaoGoodsComponent: 0x608000151a90>
[Header] <DDComponentPodDemo.HeaderComponent: 0x608000151f60>
<DDComponentPodDemo.TaobaoGoodsComponent: 0x608000151930>
<DDComponentPodDemo.TaobaoGoodsComponent: 0x608000151670>
<DDComponentPodDemo.TaobaoGoodsComponent: 0x608000152640>
-[error] <DDComponentPodDemo.StateComponent: 0x608000165340>
-[noData] <DDComponentPodDemo.StateComponent: 0x608000165400>
- View Component: displaying. for example, a list of cell or just an element。
- Container Component: combine the view components. For example, conbine some components as a list, or switch between different components(Loading, Error, Empty). And the root component is also a containter component.
- Basic components, 0 sections and multiple items need to be wrapped in containers
- Internal implementation of cell content
- Container itemgroupcomponent nesting is required
- Base component, one section multiple items.
- Internal implementation of cell, header and footer content.
- Headerview inherits this component.
- Footerview inherits this component.
- Base component, one section multiple items.
- The header is mainly HeaderComponent.
- The footer is mainly FooterComponent.
- Internal implementation of cell content.
- Container component, one section multiple items.
- The header is mainly HeaderComponent.
- The footer is mainly FooterComponent.
- Subviews are dominated by subcomponents
- Container component, multiple items.
- Subcomponents nested container components such as itemcomponent, sectioncomponent and headerfootersectioncomponent.
- Root container component, binding collectionview or tableview
- Multiple sections
- Subview subcomponents nested container components such as sectioncomponent
- State machine container component
- Use and to switch the loading, empty and normal views
- Form component, a container component of view
- Cells are not reused
An example how it
We need to do is only the red part.
Use size
, inset
first, then override the delegate
api.
As use the system api, indexPath
is the UICollectionView
's location. It is not the index of component's dataSource.