我尝试在Xamarin.iOS中的UIControllerView中管理UICollectionView。 我尝试过很多东西,比如:https://developer.xamarin.com/guides/ios/tvos/user-interface/collection-views/或者:https://www.youtube.com/watch?v=W4H9uLjoEjM
最后,我遵循了本教程:https://forums.xamarin.com/discussion/11274/how-to-setup-uicollectionview-datasource
但我仍被封锁。我的应用程序在尝试显示带有此错误的UIViewController时崩溃:[Gotago_iOS_CollectionViewSource_ViewSourceListProgram collectionView:cellForItemAtIndexPath:]: unrecognized selector sent to instance 0x7af49db0'
这是我的代码......请帮忙吗?
public partial class ViewControllerListProgram : UIViewController
{
private ViewSourceListProgram m_viewSource;
public ViewControllerListProgram(IntPtr handle)
: base(handle)
{
}
public override async void ViewDidLoad()
{
base.ViewDidLoad();
AppDelegate.CurrentViewController = this;
ApiController_GetListConseilCircuit apiCtrl = new ApiController_GetListConseilCircuit();
m_collectionView.RegisterClassForCell(typeof(CellListProgram), CellListProgram.Id);
m_viewSource = new ViewSourceListProgram(await apiCtrl.OnlineGetListConseilCircuit());
m_collectionView.Source = m_viewSource;
}
}
public class ViewSourceListProgram : UICollectionViewSource
{
public List<ApiController_GetListConseilCircuit.ConseilCircuit> m_lsCircuits;
public ViewSourceListProgram(List<ApiController_GetListConseilCircuit.ConseilCircuit> lsCircuits)
{
m_lsCircuits = lsCircuits;
}
public override nint NumberOfSections(UICollectionView collectionView)
{
return 1;
}
public override nint GetItemsCount(UICollectionView collectionView, nint section)
{
return m_lsCircuits.Count;
}
public override bool ShouldHighlightItem(UICollectionView collectionView, Foundation.NSIndexPath indexPath)
{
return true;
}
public override void ItemHighlighted(UICollectionView collectionView, Foundation.NSIndexPath indexPath)
{
CellListProgram cell = (CellListProgram)collectionView.CellForItem(indexPath);
Toast.MakeText("Cell highlighted", Toast.LENGTH_LONG).Show();
}
public override void ItemUnhighlighted(UICollectionView collectionView, Foundation.NSIndexPath indexPath)
{
CellListProgram cell = (CellListProgram)collectionView.CellForItem(indexPath);
Toast.MakeText("Cell unhighlighted", Toast.LENGTH_LONG).Show();
}
public UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
{
CellListProgram cell = (CellListProgram)collectionView.DequeueReusableCell(CellListProgram.Id, indexPath);
ApiController_GetListConseilCircuit.ConseilCircuit circuitOrProgram = m_lsCircuits[indexPath.Row];
return cell;
}
}
public partial class CellListProgram : UICollectionViewCell
{
public static readonly NSString Id = new NSString("programCell");
public CellListProgram (IntPtr handle) : base (handle)
{
}
}