gpt4 book ai didi

ios - deleteRowsAtIndexPaths 后 contentOffset 更改通知的任何委托(delegate)方法

转载 作者:行者123 更新时间:2023-11-28 17:34:11 24 4
gpt4 key购买 nike

在使用 deleteRowsAtIndexPaths:withRowAnimation: 删除一些底部行后,我的 TableView 的长度缩小了,它会自动向下滚动以补偿这些底部行的丢失,这意味着它的 contentOffset 发生了变化。

问题是在这种情况下没有调用scrollViewDidScroll:。我可以使用任何其他委托(delegate)方法来获得此处 contentOffset 更改的通知吗?

最佳答案

这听起来像是键值观察的用例。

尝试将此添加到您的 Controller :

        [tableView addObserver:self 
forKeyPath:@"contentOffset"
options:NSKeyValueObservingOptionNew
context:nil];

然后您可以在 Controller 中实现此方法。

-(void) observeValueForKeyPath: (NSString *)keyPath 
ofObject: (id) object
change: (NSDictionary *) change
context: (void *) context {

if ([keyPath isEqualToString:@"contentOffset"]) {

//Do Something with content offset

}

但是,由于您正在观察 contentOffset 属性,每次滚动时可能会触发此通知。我建议改为观察 contentSize 属性,它应该只在添加或删除行时触发此通知。

关于ios - deleteRowsAtIndexPaths 后 contentOffset 更改通知的任何委托(delegate)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10319969/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com