我有一組圖像,並希望具有'拖動重新排序'的功能我正在使用UICollectionView。Xamarin iOS:編輯單元格UICollectionView
如果視圖從UICollectionViewController
繼承然後我可以做到這一點直接 即
public class SimpleCollectionViewController : UICollectionViewController
{}
通過重寫CanMove
和CanMoveItem
代表。
public override bool CanMoveItem(UICollectionView collectionView, NSIndexPath indexPath)
{
//System.Diagnostics.Debug.WriteLine("Checking if it can move the item");
return true;
}
public override void MoveItem(UICollectionView collectionView, NSIndexPath sourceIndexPath, NSIndexPath destinationIndexPath)
{
//base.MoveItem(collectionView, sourceIndexPath, destinationIndexPath);
System.Diagnostics.Debug.WriteLine("Started moving item");
var item = animals[(int)sourceIndexPath.Item];
animals.RemoveAt((int)sourceIndexPath.Item);
animals.Insert((int)destinationIndexPath.Item, item);
}
但我現在的觀點是不是從UICollectionViewController繼承我怎麼能使用「UICollectionViewController」代表重新排序UICollectionView裏面的物品
我加了Objective-C和快捷的標籤,因爲這問題是與Xamarin無關,但與iOS架構相關。
謝謝。
您好@jgoldberger 的IUICollectionViewDataSource只有'GetItemCount'和'GetCell'功能。它沒有'CanMoveItem'和'MoveItem'。 – TheDeveloper
我會更新我的答案。 – jgoldberger
〜jgoldBerger,謝謝你的回答。它的工作現在。但我陷入另一個問題。當cellzise很小時,MoveItem和canMove不會被調用。只有在單元大小較大時,纔會調用MoveItem和CanMove。我在[這裏]發佈了新的問題(http://stackoverflow.com/questions/41248063/xamarin-uicollection-image-reorder-issue)你能幫我解決嗎? 謝謝。 – TheDeveloper