I've just created UITableViewCell. I added to it two buttons. Then I set transparent background to the cell.
cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
But there is a problem. When user tapped on cell it changed the color to blue. But I don't want to see any reaction when a user is tapping.
Please see screenshots.
tapped action
Update for Swift 5:
set the selection style to none
cell.selectionStyle = .none;
Don't use - cell.isUserInteractionEnabled = false
Or your buttons won't work.
There are a few ways:
1.cell.userInteractionEnabled = NO; (to make cell 'ready-only' - this includes the buttons)
2.cell.selectionStyle = UITableViewCellSelectionStyleNone; (to disable just highlighting)
3.tableView.allowsSelection = NO; (disables just highlighting for whole table)
4.tableView.UserInteractionEnabled:NO; (to make whole table 'ready-only' - including buttons)
cell.selectionStyle = UITableViewCellSelectionStyleNone;
Swift 4 solution:
// disable selection for a specific cell
cell.selectionStyle = .none
// disable selection for all cells inside your TableView
tableView.allowsSelection = false
Related
I need to set
cell.selectionStyle = UITableViewCellSelectionStyleNone;
in my tableview.I can check multiple cells to delete the rows.While doing this the default image(circle with tickmark) to selection at left is not getting displayed.Its working fine when I am setting selection styles to
` UITableViewCellSelectionStyleBlue
UITableViewCellSelectionStyleGray
UITableViewCellSelectionStyleDefault`
My question is there any way to display selection button when selection style is none in tableview ?
You can leave it with UITableViewCellSelectionStyleDefault
If you want to change the selected color of the cell:
UIView *colorView = [[UIView alloc] init];
colorView.backgroundColor = [UIColor clearColor];
[cell setSelectedBackgroundView:colorView];
Here is a UITableViewCell that opens a modal ('Add Ingredients'):
I am setting the label color to match the application's tintColor:
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.textLabel.text = #"Add Ingredients...";
cell.textLabel.textColor = [self.view tintColor];
How do I dim the text color when a UIAlertView or UIActionSheet is presented? This behavior is default for buttons and other controls, but not for a cell's text label.
I have found references to tintAdjustmentMode and tintColorDidChange, but do not know how to use either.
Or should I be adding a button to my cell? My previous experience with this approach wasn't optimal - there were side-efffects with responsiveness.
I believe you are correct. You should just be able to override the tintColorDidChange method in your CustomUITableViewCell.
http://www.qubop.com/ios7.pdf
My UITableViewCells are all pre-defined "Subtitle" style. I want to set the background image for a selected cell to another picture. I tried every which way to implement this and all methods discussed on stackoverflow seem to fail.
I tried again for some other, easier way to change the selectedBackgroundView property, like:
cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.bounds] ;
cell.selectedBackgroundView.backgroundColor = [UIColor yellowColor];
But it doesn't work as well. What's wrong with that ?
As I understand you want to set selected background image to your cell?
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"backgroundImage.png"]];
EDIT:
As i know UITableViewCell can not be highlighted after selection in such common cases:
There is somewhere set cell.selectionStyle = UITableViewCellSelectionStyleNone;
You implemented willSelectRowAtIndexPath and it returns nil;
There is set [self.tableView setAllowsSelection:NO];
May be you set self.tableView.userInteractionEnabled = NO; or cell.userInteractionEnabled = NO;
You subclassed UITableViewCell and implemented such methods not correct setSelected:animated: or setHighlighted:animated
May be share your cellForRowAtIndexPath method code to investigate the problem
You can change the highlight color in several ways.
Change the selectionStyle property of your cell. If you change it to UITableViewCellSelectionStyleGray, it will be gray.
you can also check that property in your tableView:didSelectRowAtIndexPath:
//do something like this for color
cell.selectionStyle= UITableViewCellSelectionStyleGray;
// for image
cell.selectedBackgroundView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:#"imageName"]];
Change the selectedBackgroundView property. Actually what creates the blue gradient is a view. You can create a view and draw what ever you like, and use the view as the background of your table view cells.
best of luck..
In my case the problem appeared after compiling on Xcode 13 - sdk iOS 15+
with any change to the code. Eventually I subclassed the cell and add the code:
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
[self.contentView insertSubview:self.selectedBackgroundView
atIndex:0];
self.selectedBackgroundView.hidden = !selected;
}
I know how to remove selection color from UITableViewCell with
cell.selectionStyle = UITableViewCellSelectionStyleNone
But it disable all "on press" response from view inside it... Is there any way to remove just the selection color?
Best regards,
I got the answer based on Pratik comment. Use this code to remove just the selection color.
cell.selectedBackgroundView = [[UIView alloc] init];
For group table cell, I fall into this problem.
cell.backgroundColor=[UIColor clearColor]
make the cell bg black. It works for normal cell, not for group table cell.
I want to add some button, e.g. like the detail view of iPhone contact with transparent background.
If anybody face the problem, I got a solution, set a transparent view as a background view of the cell. Then it becomes totally transparent. Then you can add more view or customize the cell.
UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor clearColor];
messageCell.backgroundView = backView;
messageCell.contentView.layer.cornerRadius = 10.0;
messageCell.contentView.layer.borderWidth = 1.0f;
messageCell.contentView.layer.borderColor = [[Settings getInstance] colorFrameBorder].CGColor;
messageCell.selectionStyle = UITableViewCellSelectionStyleNone;
return messageCell;
This solution was quoted in one of the StackOverflow question, which I cant remember.
I have also found that, its easy to add a transparent view in the table header or footer. The button down the contact details are probably added in a footer view.
From the looks of it I'd say you are setting a background image to your cell. You can see it at each cell on the right side, there are the stripes from your view background.
Remove the cell's background and you should be fine.
I found the solution from this answer here by setting cell's backgroundView
cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
I would take Charles's answer one step further and do the following
self.myTableView.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];