简体   繁体   中英

Xamarin.Forms: Custom renderer for displaying disclosure indicator on UITableViewCell

I want to show a disclosure indicator on my table view cell for iOS. I found this thread and a custom renderer has been proposed. I tried this:

[assembly: ExportRenderer (typeof (EmployeeCell), typeof (EmployeeCellRenderer))]

namespace HelloXamarinFormsWorld.iOS
{
    public class EmployeeCellRenderer : Xamarin.Forms.Platform.iOS.ViewCellRenderer
    {
        public override UITableViewCell GetCell (Cell item, UITableView tv)
        {
            var cell = base.GetCell (item, tv);

            cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;

            return cell;
        }
    }
}

This file is called EmployeeCellRenderer and can be found in the root directory of the iOS solution. Such a custom renderer can be also found here .

If I want to compile this I get

Error CS0115: `HelloXamarinFormsWorld.iOS.EmployeeCellRenderer.GetCell(Xamarin.Forms.Cell, UIKit.UITableView)' is marked as an override but no suitable method found to override (CS0115) (HelloXamarinFormsWorld.iOS)

These are my includes:

using System;
using HelloXamarinFormsWorld;
using Xamarin.Forms;
using HelloXamarinFormsWorld.iOS;
using UIKit;

How can I add a disclosure indicator to my table view cell?

The signature of the GetCell() method changed. It is now:

public override UIKit.UITableViewCell GetCell (Xamarin.Forms.Cell item, UIKit.UITableViewCell reusableCell, UIKit.UITableView tv)
{
    return base.GetCell (item, reusableCell, tv);
}

The reason for the change is the support for reusing cells.

The easiest way to figure these things out is to simply type override in your code file, followed by a blank (space). Intellisense will then show all overridable methods of the base class(es).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM