【问题标题】:ItemSelected not called - Xamarin.iOS F#未调用 ItemSelected - Xamarin.iOS F#
【发布时间】:2018-01-30 13:20:37
【问题描述】:

我有一个UICollectionViewController 定义如下:

    [<Register ("LandlordHome")>]
type LandlordHome (handle:IntPtr) = 
    inherit UICollectionViewController (handle)


    override x.ViewDidLoad () =
        base.ViewDidLoad ()

        let collectionViewDelegate = new CollectionViewFlowDelegate(new IntPtr())
        collectionViewDelegate.parent <- x

        x.CollectionView.Delegate <- collectionViewDelegate

为了清楚起见,我省略了不相关的代码。

接下来,我有一个UICollectionViewDelegateFlowLayout,定义如下:

    [<Register ("CollectionViewFlowDelegate")>]
type CollectionViewFlowDelegate (handle:IntPtr) = 
    inherit UICollectionViewDelegateFlowLayout (handle)

    let mutable parentViewController : UIViewController = null

    member this.parent 
        with get() = parentViewController 
        and set(value) = parentViewController <- value

    override x.ItemSelected(collectionView : UICollectionView, indexPath : NSIndexPath) = 
        let controller = new ChatControllerLandlord(new IntPtr())
        controller.GetListingId <- ""
        controller.GetPartnerId <- ""
        controller.GetLandlordId <- ""
        controller.GetPartnerName <- ""
        parentViewController.PresentViewController(controller,true,null)

这样做是为了覆盖ItemSelected 方法,以便当我点击UICollectionViewCell 时执行其中的代码。

但是,当我点击单元格时,什么也没有发生。

【问题讨论】:

    标签: ios f# xamarin.ios uicollectionview uicollectionviewdelegateflowlayout


    【解决方案1】:

    我试过你的代码,找到了解决方法。

    修改CollectionViewFlowDelegate的构造方法如下:

    let collectionViewDelegate = new CollectionViewFlowDelegate()
    collectionViewDelegate.parent <- x
    x.CollectionView.Delegate <- collectionViewDelegate
    
    
    type CollectionViewFlowDelegate () = 
    inherit UICollectionViewDelegateFlowLayout ()
    

    【讨论】:

      猜你喜欢
      • 2017-08-11
      • 1970-01-01
      • 2017-12-03
      • 2017-01-11
      • 1970-01-01
      • 1970-01-01
      • 2016-03-03
      • 2017-04-06
      • 2017-02-04
      相关资源
      最近更新 更多