I have an enhanced listview (Helpers) which is working fine on Xamarin Forms project. But when I migrate it to MAUI my app is breaking with below exception.
System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Maui.Controls.Compatibility.Platform.iOS.CellTableViewCell.GetNativeCell(UITableView , Cell , Boolean , String ) at Microsoft.Maui.Controls.Compatibility.Platform.iOS.ListViewRenderer.ListViewDataSource.GetCell(UITableView , NSIndexPath ) at UIKit.UIApplication.UIApplicationMain(Int32 , String[] , IntPtr , IntPtr ) at UIKit.UIApplication.Main(String[] , Type , Type ) at MyProject.Program.Main(String[] args) in /Users/MyCompany/Projects/MyProject-maui/MyProject/Platforms/iOS/Program.cs:line 13
Screenshot
My Code:
SingleProject
public class EnhancedListView : ListView
{
public EnhancedListView()
{
}
public void ForceNativeTableUpdate()
{
ViewCellSizeChangedEvent?.Invoke();
}
public event Action ViewCellSizeChangedEvent;
}
iOS Platform
class EnhancedListViewRenderer : ListViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
{
base.OnElementChanged(e);
if (e.NewElement is EnhancedListView enhancedListView)
{
enhancedListView.ViewCellSizeChangedEvent += UpdateTableView;
}
if(Control != null)
{
Control.SectionHeaderTopPadding = new nfloat(0);
}
}
private void UpdateTableView()
{
if (!(Control is UITableView tv)) return;
tv.BeginUpdates();
tv.EndUpdates();
}
}
Android part is working fine without any enhanced renderers. It is expanding and collapsing when data is visible on the UI.