Semi-Selection of Custom UITableViewCell Corrupts UILabel Drawing - ios

Tapping and then rolling your finger off of my UITableView's custom UITableViewCell corrupts the drawing of the contained UILabel. Neither setSelected: nor setHighlighted: are called. The UITableView uses dynamic prototypes. Tapping the cell results in normal selection and drawing. Here is a video showing what happens:
http://www.youtube.com/watch?v=vMHQc5tpcOY
I do custom drawing in a subclassed CALayer. Any guidance in resolving is appreciated.

I was able to resolve this by overriding setHighlighted as described in this answer.

Related

New UITableViewCell not calling subview drawRect()

I am having this problem for the past two days and I'm trying to get my head around it with no good result.
I have a UITableView with custom UITableViewCell. Inside the UITableViewCell I have a custom UIView that I subclassed and drawing it by calling its own drawRect.
The drawing for reused cells has no issues and the cell is calling its own drawRect and the custom subview is calling its own drawRect as well.
The problem arises when a new cell is dequeued, the custom subview drawRect is not called at all leaving that view empty (non visible)
What I did:
calling subview.setNeedsDisplay has no effect, it's redrawing the reused cells' custom subview but it has no affect on drawing the newer cells' custom subviews.
That's the only thing I thought of and was obvious to try.
Is there a way to force drawing for the subviews for new UItableViewCell?
Have you tried calling [cell setNeedsDisplay] but on the main thread?
I managed to solve the issue and force the redrawing of the subview of a custom cell by implementing heightForRowAtIndexPath regardless of the iOS version (>=7)
Apparently iOS redraw the cell after the height is being calculated.

Drawing in screen with finger in UITableView

I am following this excellent small tutorial about drawing on screen in the layer of a UIView (subclass).
http://spritebandits.wordpress.com/
It just works.
There is just one thing. I placed this view as subview of a UITableViewCell which, naturally, is displayed as part of a UITableView.
I guess I would have the same issue when I would place it within an UIScrollView. (UITableView inherits from UIScrollView anyway)
Touches are triggered by my painting view as long as their related movement is horizontal. As soon as I move the finger kinda vertical, even partly, then the UITableView takes over and scrolls the table.
Is there any proper way of stopping the Table to taike control of the touches while the touch is actually within my view?
If it is of importance: I am using storyboard. The cell is a prototype cell with its own subclass of UITableViewCell.
I've implemented this using the same class "Canvas" you're saying and also inside a UITableViewCell. But I didn't use the entire cell for drawing, only a UIView inside of the UITableView as a subview.
I reached the whole user experience by activating and deactivating the UITableView scrolling when that UIView (subview of the cell where I allow the drawing) fires touchesBegan or touchesEnded. So when they touch/move inside the UIView, they're drawing. When it's outside, they're scrolling. So they can't scroll on the UIView because they will be drawing.
The problem in your case is that since the whole cell is the view for drawing, the user cannot scroll in this concrete cell because it's the drawing one.
Hope this will help.
I dont have an answer for that. But there is essentially a work around.
You could get the user in to a drawing mode, where the scrolling for a UItableviewcell is disabled and then
once the user is done with drawing, you could enable scrolling again.
Inclusion of a button anywhere on the screen would help you switch modes.

UIScrollView within UICollectionViewCell Not Working

I have a UICollectionView with a custom UICollectionViewCell. The UICollectionView scrolls horizontally, with each cell occupying all of the visible screen.
The UICollectionViewCell has a UIView subview, which in turn has a UIScrollView subview.
The UIScrollView is intended to scroll vertically, but it's not scrolling at all. I've tried setting the scroll view's contentSize with no success.
I suspect that the UIScrollView is not getting any touch events rather than it being a size issue.
Any suggestions?
EDIT >>
I'm now sure it's an event problem rather than anything specific to the UIScrollView.
I've now overridden the pointInside: method in the UIView in the UICollectionViewCell and can see that it now returns false every time I tap on it. In that case you'd think that the tap event would propagate to the next subview , but the UIView still isn't getting events. I've tried adding a UIGestureRecognizer to the UIView but it never registers a tap.
Could there be anything here intercepting the events that I'm not aware of?
I've been trying to solve a similar problem with a scrollview, and your edit about events reminded me of this question (which solved my problem again) How can I use a UIButton in a UICollection supplementary view?
Its possible you need to be using a UICollectionReusableView, not a UICollectionViewCell. Changing the class worked for me because I was using a button (and recently a scrollview) in a header.
However I've not tried for cells themselves. For capturing events from a UICollectionViewCell, maybe the following may help?
Getting button action : UICollectionView Cell
Try to disable userInteractionEnabled for the UIView and enable it for your UIScrollView
I'm not sure if this was your problem, but it was mine - and I'm putting it here in case anyone else comes across this for the same reason. I wanted to put a UIScrollView inside a UICollectionReusableView but by accident I had created my custom class as;
class CustomCellHeader: UICollectionViewCell {
}
instead of;
class CustomCellHeader: UICollectionReusableView {
}
Once I changed that, the UIScrollView within my header cell came to life!
Embed the scrollable content in a ScrollView within the cell.
Add "UICollectionViewDelegateFlowLayout" to the UICollectionViewCell i.e.:
class SomeCollectionCell: UICollectionViewCell, UICollectionViewDelegateFlowLayout {
}
Now scrolling within the cell should work.

Subviews of UITableViewCell are not visible while reordering

When I reorder my UITableViewCells, the Subviews of the Cell are not visible while dragging...I get always the same result, whether I add the Subviews programmatically in a UITableViewCell Subclass or in Storyboard...
Is there a possibility to see the real UITableViewCell with Subviews while dragging?
Ok I found a solution by my self...
For some reason the mysterious reordering animation from Apple cant capture simple UIViews, but with UIImageViews, UIButtons and UILabels as Subviews of the custom TableViewCell, the animation works like expected...creepy!

UITableViewCell customization, where to attach subviews?

when subclassing UITableViewCell to define a complete custom cell what style to set? UITableViewCellStyleDefault? Actually I don't need neither the label or the imageView, would they be allocated the same?
So when attaching my custom views to the UITableViewCell subclass, is it better to add to self, or to self.contentView?
And is it ok to do some quartz drawing in drawRect in the UITableViewCell subclass (Like background) ?
Thanks
when subclassing UITableViewCell to define a complete custom cell what style to set? UITableViewCellStyleDefault? Actually I don't need neither the label or the imageView, would they be allocated the same?
Since you are not using any of the pre-defined UILabel or UIImageView subviews of UITableViewCell, it doesn't really matter. I just use UITableViewCellStyleDefault. I do not know for sure if the UILabels or the UIImageView are allocated or not. However, since there is no way to explicitly tell the UITableViewCell not to create those subviews, I wouldn't worry about it. Even if they are created, you aren't using them so drawing the cell will not be any slower, and since cells are reused as you scroll through the table, allocating just a few extra objects once is not going to affect your overall table view performance.
So when attaching my custom views to the UITableViewCell subclass, is it better to add to self, or to self.contentView?
All of the content should be put in the UITableViewCell contentView. This will ensure that the contents behave properly when the UITableView has an index on the right or if the UITableView (or UITableViewCell) go into editing mode.
And is it ok to do some quartz drawing in drawRect in the UITableViewCell subclass (Like background) ?
The recommended approach is for the background to be placed in the UITableViewCell backgroundView property. So I would not recommend doing any drawing in the UITableViewCell subclass itself. Just use the contentView, backgroundView, and selectedBackgroundView properties. You can create a simple UIView subclass and just set that as the backgroundView of the UITableViewCell, if you like.
If you want to create a custom UITableViewCell, my experience is that it's much easier to use IB instead of code--even if you prefer using code normally. I would definitely recommend taking a look at these two links:
Creating a custom UITableViewCell in iOS 4
Custom UITableViewCell
This sounds like exactly what you're looking for -- you don't have to use the label or the image in this case, and you can make outlets to any custom UIViews that you need.
what style to set? UITableViewCellStyleDefault?
it depends on your aims. The most used style is UITableViewCellStyleDefault.
See Using Cell Objects in Predefined Styles
is it better to add to self, or to self.contentView?
developer.apple.com recommends to add subview to self.contentView (they specially call it as contentView).
is it ok to do some quartz drawing
It also depends on your aims. If you use only images or colors for background, then customize your cell view in IB, I don't see the reasons to use qurtz framework.

Resources