【问题标题】:NativeScript ListView. Get position of first visible item iOSNativeScript 列表视图。获取第一个可见项目iOS的位置
【发布时间】:2016-08-04 14:00:09
【问题描述】:

请帮忙。如何在 iOS 上获得第一个可见项目位置?

对于 Android,我有这段代码,它可以工作

restListing.android.getFirstVisiblePosition()

【问题讨论】:

    标签: ios listview nativescript


    【解决方案1】:

    NativeScript 的 ListView 在 iOS 中使用 UITableView。 也许这样的事情对您的情况有用:

    var list = <ListView>page.getViewById("list");
    var visibleCells = list.ios.visibleCells;
    console.log(visibleCells);
    console.log(visibleCells[0]); // first visible cell
    

    【讨论】:

      【解决方案2】:

      Nick's Answer 上扩展,以下代码将返回与android 对应的相同类型。

      /**
       * Get first visible item from a ListView instance.
       *
       * @returns first visible item (platform agnostic).
       * @param listView {N} ListView instance.
       */
      function firstVisibleItemIndexFromListView(listView: ListView): number {
        if (isAndroid) return listView.android.getFirstVisiblePosition();
      
        // Feel free to remove the UITableView casting, it works either way.
        // This just allows for type-checking and type-hinting!
        const tableView = listView.ios as UITableView;
        const visibleIndexes = tableView.indexPathsForVisibleRows;
        return visibleIndexes[0].row;
      }
      

      我希望这对新的 NativeScript 开发人员有所帮助!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-02-09
        • 2021-02-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-30
        • 1970-01-01
        相关资源
        最近更新 更多