MonoTouch Custom UITableViewCell AccessoryView is Null - ios

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?

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.

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.

Related

Setting accessiblityIdentifier on a UITableViewCell's accessoryView when it was created using accessoryType

As the title says, I'm trying to set an accessibilityIdentifier on the accessoryView of a UITableViewCell. The issue is that the accessoryView is created by setting the accessoryType to UITableViewCellAccessoryDisclosureIndicator. This seems to make the accessoryView property of the UITableViewCell nil, which is expected based off of Apple's documentation.
My question, then, is whether or not it is possible to set an accessibilityIdentifier on the view that iOS creates when you set the accessoryType on a UITableViewCell. When printing the view hierarchy, I see a UIButton that is created with the chevron disclosure, but can't find any way to access that view in code.
Any ideas? Is this even possible?

UISearchController messes with Layout of Cells

I am using a UISearchController in my application following this tutorial:
Now having set up a custom UITableViewCell. The UISearchController messes with my cells.
It seems like the UISearchController is not using the same custom UITableViewCell and it's view bounds differ from my own UITableView. Is there a way to change this back, when I press the cancel button?
Edit:
Though, nobody has answered, I found a solution:
make sure, your cell is connected to the actual tableView, not your primary only. ( I have used an Outlet and set only the cells of my outlet )
make sure you ALWAYS address the outlets in your custom cell. Since I used this
cell.textLabel?.text = "Hello"
my cell will automatically be cast to the default cell.

UIPickerView in UITableViewCell showing behind next Cell

I have a tableview with a number of custom cells. The problem I am having is that the cell with the pickerview is 'bleeding' behind the neighboring cell.
Once I push another view controller and pop back, the neighboring cell is properly opaque until I manipulate the picker, at which point the issue materializes again.
The cell is, in fact, opaque. I have set it as such in both the storyboard and code. I have also tried setNeedsLayout and layoutIfNeeded in cellForRowAtIndexPath.
Set clipsToBounds property to true to each cell in the method cellForRowAtIndexPath.
You can set this property in the Storyboard if you are using prototypes cells.
You need to provide more information.
But if I understand correctly, you should hide the cell that contains the picker and only show it when the user will input.
Here is a tutorial on how to hide the cell, like the calendar iOS app does.
http://www.appcoda.com/expandable-table-view/

Change UITableViewCell background color in Interface builder

I'm trying to avoid adding any code to my iOS project that has to do with visual set up since that's what Interface Builder is supposed to streamline for you.
So I'm trying to set up the prototype cell in IB and then just call:
TableCell *cell = [self.tableView dequeueReusableCellWithIdentifier:#"TableCell"];
The problem is if I change the background color for the cell in IB it remains white when I run my application. I can preset the color of the label fine but not the background color attribute in the Table Cell.
As an additional note, I can see that the UIView that is the backgroundView inside the cell is null after breakpointing and inspecting the variable after it's been initialized.
UPDATE
I'm getting the impression that the option for background color in IB is essentially useless? I'd rather not believe that.
You cannot do that unfortunately.
Change the background colour of the cell in tableView:willDisplayCell:forRowAtIndexPath:
From the documentation of UITableViewCell:
Note: If you want to change the background color of a cell (by setting the background color of a cell via the backgroundColor property declared by UIView) you must do it in the tableView:willDisplayCell:forRowAtIndexPath: method of the delegate and not in tableView:cellForRowAtIndexPath: of the data source. Changes to the background colors of cells in a group-style table view has an effect in iOS 3.0 that is different than previous versions of the operating system. It now affects the area inside the rounded rectangle instead of the area outside of it.
In interface builder, add a view as a subview of the cell, that will be your background view. You can then add all labels or anything else as subviews to that view. Change that views background color as you want.
I think this is probably a bug in IB. You can add views to that bar at the bottom of the controller, and then connect those views to the backgroundView and selectedBackgroundView properties of the cell. However, the backgroundView's color doesn't work, while the selectedBackgroundView's color does work correctly. If you add a background view in code to a custom table view cell and give it a backgroundColor, that does work.

UITableView cell selection disabled and UITableViewHeader Enabled

I am adding a my header view to
self.tableView.tableHeaderView=headerView;
This tableView has 10 cells.
I want to disable the cell Selection but, headerView touch events must be enabled.
To achieve this I added the following code:
self.tableView.userInteractionDisabled=YES;
self.headerView.userInteractionDisabled=NO;
self.headerView.exclusiveTouch=YES;
Where I am wrong?
Basic idea of implementation is , If headerView is enabled then cell selection is disabled and vice-versa.
I'm not sure that I completely understand what you are asking, but if you want to avoid seeing any cell highlighting set the UITableViewCell selectionStyle to UITableViewCellSelectionStyleNone. That's what I do, and then don't implement the UITableViewDelegate method tableView:didSelectRowAtIndexPath:.
I've never tried it, but I'm pretty sure you can also disallow the selection of any rows by setting the UITableView property allowsSelection to NO.
The userInteractionDisabled property of the table view should be set to NO. Otherwise your headerView, which is a subview of tableView, will not get touch events. Setting a superview's userInteractionDisabled property to no disables touch events for all of its subviews.

Resources