Selected cell hides the cells UITextView subviews - ios

My Tableview cells expand when tapped, to show more information in 3 UITextViews.
But the cell changes color (as i want it to), and this hides the UITextViews, but not the other subviews as you can see in the image below.(orange lines indicate the textviews).
Changing the color of the textview background makes no difference.
What could i try?
EDIT ------ new image with TextFields.

This issues caused by UITableViewCell selection. When you select cell it changes backgroundColor on all subviews. To prevent this you have two options:
1) Subclass UITableViewCell and set color to subviews in:
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
2) Setup color in tableView:didSelectRowAtIndexPath::
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([cell isSelected]) {
UIView *view = [cell viewWithTag:TEXTFIELD_TAG];
view.backgroundColor = [UIColor greenColor];
}
}

If i have not misunderstood the question then You can try adding all these three text view in one uiview(container) . Then on didselect table view cell change the background color of that container view. Hope it helps.

Have your cell selection style to none and override setSelected method of tableView cell to change background color of cell.
{
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
#implementation CustomTableViewCell
-(void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
//--
self.contentView.backgroundColor = (selected) ? [UIColor grayColor]:[UIColor whiteColor];
}
#end

Related

Changing alpha of UITableViewCell when selected does nothing

Following the advice in this answer Custom UITableViewCell selection style? about how to make a custom selection style for a UITableViewCell I did the following.
First, in my custom view controller, which has a UITableView as a property and which serves as its datasource and delegate I have the following:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//UITableViewCell *cell;
NavTableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:#"Cell"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
Then this is my entire custom UITableViewCell:
#import "NavTableViewCell.h"
#implementation NavTableViewCell
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
[super setHighlighted:highlighted animated:animated];
if(highlighted){
self.contentView.alpha = .5;
}else{
self.contentView.alpha = 1;
}
}
#end
I have also tried putting the code in setSelected. In both cases I don't see any change in my selected/highlighted table view cell. I have tried changing its color and changing the colors of the labels within it, but there is simply no change. I have also tried going through all the kinds of selection styles for the cell, all to no avail as far as seeing my customization.
What am I doing wrong?
From the documentation:
You can use selectedBackgroundView to give the cell a custom appearance when it is
selected. When the cell is selected, this view is layered above the
backgroundView and behind the contentView.
So whatever you want to do to your cell while selecting it, you have to do it for the selectedBackgroundView .
Try this:
UIView *highlightView = [[UIView alloc] init];
highlightView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:1.0 alpha:.5];
cell.selectedBackgroundView = highlightView;

AsyncDisplayKit CellNode setting highlighted color

I'm using Async Display Kit to display cell nodes in an ASTableView. How can I set a custom color for the cell node's selected state. With normal tableView cells I would just override
(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
in my cell implementation, but that method doesn't exist on ASCellNodes. Has anyone else encountered this problem and how did you solve it?
Assuming you've subclassed ASCellNode to create your own cells, you could just add your own setHighlighted method.
e.g.
- In Your ASCellNode Subclass
- (void)setHighlighted:(BOOL)highlighted {
if (highlighted) {
self.backgroundColor = [UIColor blueColor];
} else {
self.backgroundColor = [UIColor whiteColor];
}
}
- In Your Delegate Implementation
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MyNodeSubclass * node = (MyNodeSubclass *)[(ASTableView *)tableView nodeForRowAtIndexPath: indexPath];
[node setHighlighted: YES];
}
Note:
You'll need to maintain your own state in regards to which cells are selected/deselected

Change background color of accessoryView in UITableViewCell

I have a custom cell (not using xib), and I'm trying to change the background color of the accessory view. Here is my code and what I tried"
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
customCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cellID" forIndexPath:indexPath];
cell.accessoryView.backgroundColor = [UIColor redColor];
return cell;
}
Results:
The background color didn't change.
You can do this in either of two ways. You can change the table view's tint color, which will change the color of the accessory, or you can drag in any view or control you want, and change its color to whatever you want.

Tableview cell separating line disappears when tapped

I have a UITableView with custom tableview cells with the separator line between each cell. I recently began implementing multi cell selection when in editing mode. In order to have the blue circled checkmarks when each cell is selected, I changed cell selectionStyle from UITableViewCellSelectionStyleNone to UITableViewCellSelectionStyleDefault. To get rid of the gray shade when the cell is selected I just implemented a white background like this:
UIView * cellBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
cellBackgroundView.backgroundColor = [UIColor clearColor];
cell.multipleSelectionBackgroundView = cellBackgroundView;
cell.selectedBackgroundView = cellBackgroundView;
The problem is that when I'm not in edit mode, the separator line disappears whenever the cell is selected, but when I select a cell in edit mode, the line remains. Any idea how to resolve this so the separator always remains?
try following:
Add this lines
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[tableView reloadRowsAtIndexPaths:#[indexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];
at the begining of didSelectRowAtIndexPath
this is weird bug which exists since iOS7.0
I know that the cell separator disappearing is a common issue, but none of the current solutions seemed to solve my problem so I came to the conclusion that I would need to toggle my selectionStyle to UITableViewCellSelectionStyleNone when my tableView is not in editing mode and UITableViewCellSelectionStyleBluewhen I'm in editing mode. I was able to achieve this by calling the following in my view controller containing my table view:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(tableView.editing)
{
[((customTableViewCellClass*)[tableView cellForRowAtIndexPath:indexPath]) changeSelectionStyle:YES];
}
else
{
[((customTableViewCellClass*)[tableView cellForRowAtIndexPath:indexPath]) changeSelectionStyle:NO];
}
return indexPath;
}
Then in my custom tableviewcell class I call the following:
-(void) changeSelectionStyle: (BOOL) selected
{
if(selected)
{
self.selectionStyle = UITableViewCellSelectionStyleBlue;
}
else
{
self.selectionStyle = UITableViewCellSelectionStyleNone;
}
}
In cellForRowAtIndexPath I left the code that changed the view for multipleSelectionBackgroundView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UIView * cellBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
cellBackgroundView.backgroundColor = [UIColor clearColor];
cell.multipleSelectionBackgroundView = cellBackgroundView;
cell.selectedBackgroundView = cellBackgroundView;
}

UITableViewCell allways show some subview

I have some UITableViewCell with some subview. I need this subview to be shown on the top of the cell is selected and not. The problem is that this cell has selectedBackgroundView which hides my needed subview on select.
UIView *bgView = [[UIView alloc] initWithFrame:cell.bounds];
bgView.backgroundColor = someColor;
cell.selectedBackgroundView = bgView;
I tried also cell.selectedBackgroundView addSubview: but it didn't help.
So the question is: How to add some subview to the cell to make it be on the top if cell is selected?
set cell.selectionStyle = UITableViewCellSelectionStyleNone;
if you have a custom Cell, you can implement
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
[self bringSubviewToFront:myCustomView];
}
if not, the logic is the same, just in the
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
method ;)
You must add your subviews to the contentView of the tableViewCell and not the cell directly.
Even if it is a custom subclass of UITableViewCell that you have implemented, you must add other subViews to the contentView of the tableViewCell. The contentView and it's subviews will not be hidden when the cell is selected.
[cell.contentView addSubview:yourView];

Resources