因此,我有一个UITableViewCell子类,需要知道UITableView当前是否正在滚动或不更新UI。所以我不得不指向子类中的UITableView财产,我有以下方法代表了UIScrollView的委托:检查UIScrollView是否从子区域滚动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat scrollOffset = scrollView.contentOffset.y;
CGFloat contentHeight = scrollView.contentSize.height - kLoadMoreOffset;
if (scrollOffset >= contentHeight && loadMore && [self.nextPaginationURL_ isNotNull]){
loadMore = NO;
[self loadMore];
}
self.isScrolling = [NSNumber numberWithInt:1];
}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (!decelerate){
self.isScrolling = [NSNumber numberWithInt:0];
NSLog(@"FIRING NOTIF END DRAGGING");
[self showLoadMore];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSLog(@"FIRING NOTIF END DECEL");
self.isScrolling = [NSNumber numberWithInt:0];
[self showLoadMore];
}
正在滚动本质上是一个NSNumber的指示滚动视图是否滚动与否。我将这个传递给UITableViewCell以便稍后在类中使用,以查看状态是否正在滚动。我打算使用KVO,但仅仅使用BOOL是不可能的(或者如果有可能让我知道)。有没有更优雅的方式来做到这一点?
我有我的UITableViewCell的指派属性如下
@property (nonatomic, assign) BOOL isScrolling
,当我INITING我的UITableViewCell子类,我assinging与isScrolling上的UITableView isScrolling。我想我最关心的这种方法是,如果我改变了UIScrollView委托的isScrolling,UITableViewCell子类的isScrolling属性是否也反映了这种变化?