@@ -33,7 +33,9 @@ @interface ShopViewController ()<UICollectionViewDataSource,UICollectionViewDele
3333}
3434
3535@property (nonatomic ,strong )XTSegmentControl *shopSegmentControl;
36+ @property (nonatomic ,strong )UICollectionView *collectionView;
3637@property (nonatomic ,strong )Shop *shopObject;
38+
3739@end
3840
3941@implementation ShopViewController
@@ -63,7 +65,6 @@ - (void)bannerClicked:(NSString *)linkStr{
6365}
6466
6567
66-
6768#pragma mark-
6869#pragma mark---------------------- ControllerLife ---------------------------
6970
@@ -94,7 +95,6 @@ - (void)viewDidAppear:(BOOL)animated
9495 _isRequest = YES ;
9596 [self requestgiftsList ];
9697 }
97-
9898}
9999
100100#pragma mark-
@@ -112,14 +112,15 @@ - (void)refreshMore{
112112- (void )requestgiftsList {
113113
114114 [self .view beginLoading ];
115+ __weak typeof (self) weakSelf = self;
115116 [[Coding_NetAPIManager sharedManager ] request_shop_bannersWithBlock: ^(id data, NSError *error) {
116- _shopObject .shopBannerArray = data;
117- [_collectionView reloadData ];
117+ weakSelf. shopObject .shopBannerArray = data;
118+ [weakSelf.collectionView reloadData ];
118119 }];
119120
120121 [[Coding_NetAPIManager sharedManager ] request_shop_userPointWithShop: _shopObject andBlock: ^(id data, NSError *error) {
121122 if (data) {
122- [ self loadGiftsList ];
123+ [weakSelf loadGiftsList ];
123124 }
124125 }];
125126}
@@ -130,7 +131,7 @@ - (void)loadGiftsList
130131 [[Coding_NetAPIManager sharedManager ] request_shop_giftsWithShop: _shopObject andBlock: ^(id data, NSError *error) {
131132 [weakSelf.view endLoading ];
132133 if (data) {
133- [_collectionView reloadData ];
134+ [weakSelf.collectionView reloadData ];
134135 }else
135136 [NSObject showHudTipStr: @" Error" ];
136137 }];
@@ -170,24 +171,27 @@ - (void)setUpSegmentControl
170171{
171172 // 添加滑块
172173 NSArray *_segmentItems = @[@" 全部商品" ,@" 可兑换商品" ];
173- // __weak typeof(_shopSegmentControl) weakCarousel = _shopSegmentControl ;
174+ __weak typeof (self) weakSelf = self ;
174175 _shopSegmentControl = [[XTSegmentControl alloc ] initWithFrame: CGRectMake (0 , CGRectGetHeight (_collectionHeaderView.frame)- kMySegmentControl_Height - 5 , kScreen_Width , kMySegmentControl_Height ) Items: _segmentItems selectedBlock: ^(NSInteger index) {
175- if (index == _oldSelectedIndex) {
176- return ;
177- }
178- _oldSelectedIndex = index;
179- _shopObject.shopType = index;
180- [_collectionView reloadData ];
181- if (_collectionView.contentOffset .y > CGRectGetHeight (_collectionHeaderView.frame ) ) {
182- [_collectionView setContentOffset: CGPointMake (0 , CGRectGetHeight (_collectionHeaderView.frame)) animated: NO ];
183- }
184-
176+ [weakSelf segmentControlSelecteIndex: index];
185177 }];
186178 _shopSegmentControl.backgroundColor = [UIColor whiteColor ];
187179 [_collectionHeaderView addSubview: _shopSegmentControl];
188180 [self .view bringSubviewToFront: _shopSegmentControl];
189181}
190182
183+ - (void )segmentControlSelecteIndex : (NSInteger )index
184+ {
185+ if (index == _oldSelectedIndex) {
186+ return ;
187+ }
188+ _oldSelectedIndex = index;
189+ _shopObject.shopType = index;
190+ [_collectionView reloadData ];
191+ if (_collectionView.contentOffset .y > CGRectGetHeight (_collectionHeaderView.frame ) ) {
192+ [_collectionView setContentOffset: CGPointMake (0 , CGRectGetHeight (_collectionHeaderView.frame)) animated: NO ];
193+ }
194+ }
191195
192196
193197#pragma mark - UICollectionViewDataSource
@@ -226,7 +230,6 @@ - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UIColl
226230 height = kMySegmentControl_Height + bannerHeight ;
227231 _collectionHeaderView.frame = CGRectMake (0 , 0 , kScreen_Width , height);
228232 }
229-
230233 return UIEdgeInsetsMake (5 + height, 10 , 10 , 10 );
231234}
232235
0 commit comments