Bug 29505 - Changes to UITableViewCell.SelectedBackgroundView in ViewCell custom renderer are overridden when the ViewCell has a ContextAction
Summary: Changes to UITableViewCell.SelectedBackgroundView in ViewCell custom renderer...
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 1.4.3
Hardware: PC Mac OS
: --- enhancement
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-04-28 19:05 UTC by Cody Beyer (MSFT)
Modified: 2017-02-20 05:21 UTC (History)
7 users (show)

Tags: ac
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 29505 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Cody Beyer (MSFT) 2015-04-28 19:05:12 UTC
### Description 

The linked sample project attempts to set a background color to view cells, however this color is not respected when the cell includes a ContextAction

### Sample


### Video


### Steps to Reproduce

1. Open sample app
2. Deploy to iOS Simulator
3. Click each view cell in order

### Expected Results

All Selected view cells should be red when selected

### Actual Results

Only those without a context action are red when selected

### Version

=== Xamarin Studio ===

Version 5.9 (build 431)
Installation UUID: ad159da4-fe22-4bfe-8be6-52e4b844ec90
	Mono 4.0.0 ((detached/d136b79)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400000143

=== Apple Developer Tools ===

Xcode 6.3.1 (7703)
Build 6D1002

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 6481535
Branch: master
Build date: 2015-04-27 04:38:13-0400

=== Xamarin.Mac ===

Version: (Business Edition)

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/beyerc/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.2   (API level 17)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Build Information ===

Release ID: 509000431
Git revision: 7560726734fc7267de2fa9abed2509968deefaa8
Build date: 2015-04-17 19:25:48-04
Xamarin addins: 2e772c734ab3148054eae7bf8949f340fdeb5e5e

=== Operating System ===

Mac OS X 10.10.3
Darwin Codys-MacBook-Pro.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2015-05-14 00:37:41 UTC
I am correcting the Xamarin.Forms version number to, to correspond with the actual version of Xamarin.Forms used within the test case.

The issue here is approximately that the `ListViewRenderer` type and perhaps also the `ContextActionsCell` type are not currently designed to allow this customization. These types could likely be adjusted to allow this functionality, but I am uncertain of the engineering priority for adding this level of customizability. (Note: I am a member of the Xamarin Support team.)

At first glance at the view hierarchy, it does seem a little odd to me that there are `UITableViewCell` views nested under `UITableViewCell`views. Maybe the _contents_ of the `ViewTableCell` views can be added into the `ContextActionsCell` views rather than adding the `ViewTableCell` views in their entirety?

Here are 2 observations to provide additional context:

1. The type of `UITableViewCell` used to display ViewCells that have a ContextAction is different from the type used to display ViewCells that do not have a ContextAction:

> ViewCell with ContextAction:     Xamarin.Forms.Platform.iOS.ContextActionsCell

> ViewCell without ContextAction:  Xamarin.Forms.Platform.iOS.ViewCellRenderer.ViewTableCell

2. The `UIView` object that is created by `cell.SelectedBackgroundView = new UIKit.UIView()` is _completely discarded_ when the rendering process uses a `ContextActionsCell` rather than a `ViewTableCell`. You can see this clearly if you:

(a) Log the pointers of the original `UIView` objects that are created when setting `cell.SelectedBackgroundView`. For example, add something like this:

> Console.WriteLine("0x{0:x}", (nint)(cell.SelectedBackgroundView.Handle));

(b) Compare those original pointer values against the actual live values in the view hierarchy. For example, you can attach to the running app using Xcode, pause execution, and then dump out the view hierarchy:

> po [[[UIApplication sharedApplication] keyWindow] recursiveDescription]

You will see that only the "UITableViewCellSelectedBackground" views that are _immediate_ descendants of "Xamarin_Forms_Platform_iOS_ViewCellRenderer_ViewTableCell" views have pointers that match the original values from (a).

When one of the "Xamarin_Forms_Platform_iOS_ListViewRenderer" views contains some "Xamarin_Forms_Platform_iOS_ContextActionsCell" views, the "UITableViewCellSelectedBackground" views are instead immediate descendants of those "ContextActionsCell" views, and the "Xamarin_Forms_Platform_iOS_ViewCellRenderer_ViewTableCell" views do _not_ contain any "UITableViewCellSelectedBackground" views.
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2015-05-14 01:19:07 UTC
I should perhaps clarify:

> At first glance at the view hierarchy, it does seem a little odd to me that
> there are `UITableViewCell` views nested under `UITableViewCell`views. Maybe
> the _contents_ of the `ViewTableCell` views can be added into the
> `ContextActionsCell` views rather than adding the `ViewTableCell` views in
> their entirety?

This part of comment 1 is addressed to the Xamarin.Forms team, not to customers.
Comment 3 chaseqna 2015-05-14 14:15:12 UTC
Thank you for taking a detailed look at this issue.  You're the first to truly investigate it since I filed the original in February. 

I disagree that this is a "customization", though.  If it is a customization, there should be documentation saying that you can only use ContextActions if your ListView BackgroundColor is the default white, selection color is not allowed, and text must be dark.  I can't be the only one trying to develop a non-white themed ipad app.

Also, the latest Xamarin.iOS update ( has caused a serious issue with ContextActions.  Now, when you swipe on a selected item to reveal ContextActions, the item text slides to the left, but ContextActions don't show at all!  If you swipe on an unselected item, it works.
Comment 4 Chris King 2015-05-21 19:27:06 UTC
Would like to change the background color of a view cell but as that functionality is not available through Forms instead uses a custom renderer. Unfortunately that doesn't play nice with ContextActions. Ask is to enable the ability to set a background color for view cells and ensure ContextActions work.
Comment 5 Simon Taylor 2015-09-02 04:36:07 UTC
I need this too. Currently the selected item is showing as white on gray, which is unusable.