【发布时间】:2017-06-04 14:51:33
【问题描述】:
下面我的代码使其居中:-
- (void)centerUpNext:(NSIndexPath*)indexPath {
//[super viewDidLayoutSubviews];
[self.collectionView2 scrollToItemAtIndexPath:indexPath
atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
}
这就是我分配 indexPath 值的方式:-
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
if(result == NSOrderedDescending)
{
NSLog(@"reminderTime is later than systemTime");
self.upNextIndexPath = indexPath;
}
我会从 viewWillAppear 中调用它
-(void) viewWillAppear:(BOOL)animated
[self centerUpNext:self.upNextIndexPath];
这没有按预期工作。因为在加载集合视图后我无法将确切的单元格居中。我应该在何时何地调用此方法[self centerUpNext:self.upNextIndexPath];?
【问题讨论】:
-
首先,您是否获得了您想要获得的
indexPath?如果在viewWillAppear中执行print(self.upNextIndexPath),它是否显示了您想要居中的正确单元格?
标签: ios objective-c uicollectionview