0
votes

I am creating an custom control to display a list of accordions. On click of each accordion item it expands and displays the elements within. For this I have created a custom view renderer and I am using UiTableViewSource to build the list.

I have created Content view for Accordion header and Accordion item. The problem I am facing is I am unable to convert a Xamarin Forms Cell/View to Native cell view.

 public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
    {
        NativeiOSViewCell cell = tableView.DequeueReusableCell(cellIdentifier) as NativeiOSViewCell;
        var item = Items[indexPath.Section].ChildItems[indexPath.Row] as OverviewFilterViewCell;
        if (cell == null)
            cell = new NativeiOSViewCell(cellIdentifier, item.View);

        return cell;
    }

Basically I want to convert the Xamarin Forms Cell to equivalent Native Cell instead of recreating it again. An example : enter image description here

1

1 Answers

0
votes

Try the code below:

private UIView ConvertFormsToNative(View view, CGRect size)
{

    var renderer = Platform.GetRenderer(view);

    renderer.NativeView.Frame = size;

    renderer.NativeView.AutoresizingMask = UIViewAutoresizing.All;
    renderer.NativeView.ContentMode = UIViewContentMode.ScaleToFill;

    renderer.Element.Layout(size.ToRectangle());

    var nativeView = renderer.NativeView;

    nativeView.SetNeedsLayout();

    return nativeView;
}