Table View cell image dissappear and reappear on selection - iphone

I have a custom UITableViewCell class. I am toggling between accessoryTypes of UITableViewCellAccessoryCheckmark and UITableViewCellAccessoryNone when didSelectRowAtIndexPath is called. Here's an example of what the cells look like before and after selection:
before...
after....
My problem is this: the circle-colored views on the left hand side flicker when I select the cell. How do I keep the circles from flickering when the table cell is selected? I'm not manually doing any sort of reloading of the cell. Does it have something to do with selection state? Any help would be greatly appreciated; thanks!

I assume that in your cellForRowAtIndexPath method you are doing something like
[cell setImage:[UIImage imageNamed:#"someImage"] forState:UIControlStateNormal];
Try setting an image for UIControlStateHighlighted and see if that helps. Even if its the same image.

Yep, that was the solution. Thanks #aking63 for spiking an idea in me. By just overriding the setSelected method in my custom UITableViewCell class, and populating the indicator view the same way I was on setting up the cell, all things work as needed. No more flicker!

Related

iOS- TableViewCell expand/collapse

i want to create a a TableView with expand/collapse cells, and i thought 2 ways to achieve that:
Play with the heightForRowAtIndexPath
Create 2 different cell, with different identifier, and each time load the right one.
I want the cell to expand/collapse with animation, and the user can expand more then one cell.
Which one is better?
Thanks in advance!
Depends on your cell, before and after collapsing, and whether you want to animate it or not.
Options:
If the contents are the same, or with some small additions, and you wanna animate it. Use this option.
If the contents changes dramatically, go with this option. And I'm not sure if animation in this case is easy.
Good luck, need more help, let me know! ;D
I think you want this: https://github.com/seletz/CocoaTreeViewExample
I have made a expandable/collapsable treeview using the same code that is looking like this in my application now:
I was after something similar, I wanted to be able to show and hide contextMenu for a table view cell. So I ended up using just one cell for both expanded and collapsed state, and I had a "context menu subview" (that's what I wanted for the expanded look) and updated it's frame for the animation.
The trick is that when you want to expand/collapse you cell with a nice animation you'd better use beginUpdates and endUpdates instead of reloadData or reloadRowsAtIndexPaths:withRowAnimation: methods. Something like that:
// setContextMenuHidden:animated: updates frame and alpha for the context menu
// view (which is a subview of cell content view)
[cell setContextMenuHidden:NO animated:YES];
[self.tableView beginUpdates];
[self.tableView endUpdates];

Expanding UITableViewCell on Tap?

I need to expand a UITableView cell when I tap it (animate it as well). However I don't know the cell which is being tapped and I have seen the answer here: Can you animate a height change on a UITableViewCell when selected?
It seems to be a very popular answer, not just in the question. However, I need to get the cell, so how in the heightForRowAtIndexPath method can I get the cell?
Because I have tried this:
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
However using this in the heightForRowAtIndexPath method crashes the app as the first time it runs (when the view loads) it gets caught in an infinite loop I think.
Anyway if I was to take this approach how would you suggest i get around this issue? I need to access the cell. Or how else would you expand your tableview cell (animated)?
Carry on adjusting the height as you are.
I would suggest trying to get as much as you can from autoresizing masks as they have worked well for me in the past.
If you need finer grained control you can create a subclass and override the setFrame: method to find out when the frame is changing size and then set up animations appropriately there.

Animated change of uitableviewcell height and toggle of contents

I have a tableview with UiTableViewCells from a XIB and I want to animate a change of cell height when selected and showing/hiding some elements.
Now, for the animated change of height there's no problems, I've done it with the tutorial in this answer .
The problem is how to toggle some elements!
I can't figure out how to solve this problem! Putting on the xib the elements, they cover the cell above; by code I can't find a method to call when a cell is opened and the animation i finished!
Any ideas?
Thanks to all!
There may be an easier way than this, but one way would be instead of changing the cell height and adding the new components in the animation block, set a flag for that row that it should be expanded then in your animation block call
[tableview reloadData]
And in your
heightForRowAtIndexPath
method return the new cell height and in the
cellForRowAtIndexPath
method of your delegate return the new version of the cell with the additional elements.

How to draw a button over a last visible uitableview cell?

I need to display search button at the edge of last visible cell in uiTableView. Something like this:
I don't know how to get the right CGRect to draw this button (view) and how to redraw this, when the user scrolls the tableview.
Tnx.
The UITableView method
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath
should help you.
You may need to offset this by the tableview.frame.origin if you are drawing it in the parent view.
Hope this helps!
Another way would be to have the button attached to the View (rather than cell), On tapping the button you could find the NSIndexPath for last cell by iterating through visibleCells.

Custom UITableViewCell Subclass works fine, but subViews don't autohighlight when Selected

My UITableViewController uses a custom UITableViewCell Subclass.
The subClass (QuoteCell - loaded from NIB) has a few UILabels and a UIImageView on it.
Works fine, however, when I tap on the cell, the cell highlights, but the UILabels on the cell don't reverse colors.
I thought this was stock behavior??
Any help appreciated, Thanks!
btw: There's nothing in the didSelectRowAtIndexPath method yet.
I found the answer, after reading comments from Jasarien and Prakash.
Apparently, in IB, you manually have to select a highlight color to see the behavior.
By default, UILabel color is Black and the highlight color apparently is also Black, which is strange because it has that half black, half white diagonal. I would think the behavior would be different.
Anyway, I changed the color to solid white and got the highlighted behavior I was expecting.
I wonder why you need to show the row selection?
You could do this
cell.selectionStyle = UITableViewCellSelectionStyleNone;
and handle your row selection logic as-is..
You have to write the code to swap the text colour of the label yourself.
The best place for that would probably be in -setHighlighted:animated: