我想在本机脚本的列表视图上使用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");
}
}
答案 0 :(得分:0)
您将必须将newDelegate
的JS参考保存在某个地方,否则可能会被标记为垃圾回收。
此外,我建议使用RadListView进行延迟加载,因为它具有为此目的的特定事件。