ios - Nativescript iOS 委托 listView(延迟加载?)
问题描述
我想在 nativescript 中的列表视图上使用 onScroll 事件,但该事件不存在。所以我通过本机,所以我想为我的列表视图创建一个委托。一切正常,但我不知道为什么,我必须创建一个 console.log 我的委托才能使用它,否则它不会运行。你知道原因吗?
export class ItemsComponent implements OnInit, AfterViewInit {
items: Array<Item>;
@ViewChild('header') header: ElementRef;
@ViewChild('listView') listView: ElementRef;
// This pattern makes use of Angular’s dependency injection implementation to
// inject an instance of the ItemService service into this class.
// Angular knows about this service because it is included in your app’s main NgModule,
// defined in app.module.ts.
constructor(private itemService: ItemService, private zone: NgZone) { }
ngOnInit(): void {
this.items = this.itemService.getItems();
}
ngAfterViewInit() {
setTimeout(() => {
if (isIOS) {
let newDelegate = newUITableViewDelegateImpl.initWithOriginalDelegate(this.listView.nativeElement._delegate);
this.listView.nativeElement.ios.delegate = newDelegate;
console.log(this.listView.nativeElement.ios.delegate);
}
}, 50)
}
}
class newUITableViewDelegateImpl extends NSObject implements UITableViewDelegate {
public static ObjCProtocols = [UITableViewDelegate];
private _originalDelegate: UITableViewDelegate;
public static initWithOriginalDelegate(originalDelegate: UITableViewDelegate): newUITableViewDelegateImpl {
console.log("initWithOwner")
let delegate = <newUITableViewDelegateImpl>newUITableViewDelegateImpl.new();
delegate._originalDelegate = originalDelegate;
return delegate;
}
public scrollViewWillBeginDragging(scrollView: UIScrollView) {
console.log("scrollViewWillBeginDragging");
}
public scrollViewDidScroll(scrollView: UIScrollView) {
console.log("scrollViewDidScroll");
}
}
解决方案
您必须保存newDelegate
某处的 JS 引用,否则它可能会被标记为垃圾回收。
此外,我建议使用RadListView进行延迟加载,因为它具有用于此目的的特定事件。
推荐阅读
- c# - C# 等效于 CreateIoCompletionPort
- uwp - 是否可以在机器范围内安装 Microsoft Store 应用程序?
- javascript - 选中复选框时引导数据表保持全部禁用
- .net-core - 带日期时间的 Odata V4
- python - 输入提示中的 TensorFlow dtypes
- vba - 如果勾选了复选框,有没有办法选择文本框输入?VBA Excel
- mysql - mysql 查询 - where 子句仅对特定字段的选择有效
- python - 如何使用子图摆脱 y 轴上不必要的值?
- vba - 尝试在 VBA 脚本中调整形状的大小,但无法精确调整大小
- linux - Kubernetes NFS 挂载权限