Apollonas
Apollonas

Reputation: 667

MonoTouch Custom UITableViewCell AccessoryView is Null

I created a custom UITableViewCell in a MonoTouch app I am building. Inside the cell I am succesfully setting:

Accessory = UITableViewCellAccessory.DisclosureIndicator;

However when I attempt to change the background color of the AccessoryView my app crashes because AccessoryView is null:

AccessoryView.BackgroundColor = UIColor.White;

As a matter of fact the only view within the cell that is not null is the ContentView.

Anyone has an idea why the AccessoryView is Null?

Upvotes: 1

Views: 794

Answers (2)

Apollonas
Apollonas

Reputation: 667

My original issue was that I was adding a an Accessory to the cell but the background of that accessory would not be the same as the background of the rest of the cell. It was getting the background of the underlying table view which was not what I wanted. When I tried to set the AccessoryView.Background color to what I wanted (thinking that that was culprit), the AccessoryView was null.

What I ended up doing to solve my issue was to create a new UIView with the background color I wanted and set that as my cells BackgroundView (since that was also null initially). This fixed my issue and my cell has the proper color everywhere.

Upvotes: 1

poupou
poupou

Reputation: 43553

Accessory and AccessoryView properties are related but do not change each others.

When you set your own custom view in AccessoryView then the value of Accessory will be ignored the the UITableViewCell.

Anyone has an idea why the AccessoryView is Null?

Likewise if you set an Accessory then you do not get access to the stock view (thru the AccessoryView property) and events when supported, e.g. touch events for DisclosureButton, will be the cell (since you can't access the view).

If you want a custom looking accessory view then you can create one yourself and assign it to the AccessoryView property.

Upvotes: 3

Related Questions