Touches doesn't work on UITableView inside UIScrollView - ios

I have this strange issue. To start it all, this is how my view hierarchy
looks like:
I have a UIViewController with a UIScrollView with three separate ContainerView's inside it. Each of the ContainerView's frames (and respective UIViewControllers) are set programatically.
I open the second ContainerView with a UIView.animate(...) method. Inside this UIView/UIViewController I have a UITableView. The problem is that only the first five (and half of the sixth for some reason, but maybe that's a clue) UITableViewCell's are selectable. I have about five more UITableViewCell's which is for some reason not selectable.
I don't have any UITapGestureRecognizer's which has been the problem for some other people that I've seen. Also, if I add the TouchesBegan to either the UITableView or the UIViewController holding it, it behaves in the same manner. That will say, it only prints out when I touch the same part of the screen where the UITableViewCell's are selectable.
Is there anyone that have encountered the same issue or something similar to it that can shed some light over this?
Any help, input or thought is very much appreciated.

So I resolved this issue. For anyone else having similar problems this was because the underlying contentView of the UISrollView wasn't big enough.
Even though the UITableView, and even the views under it was visible, touches could not reach it since these are somehow registered through the UIScrollView contentView (for me, this was an UIView I added in the Interface Builder on top of the UIScrollView).
Also, if you are working with autoLayout, you have to change the contentViews constraints in the Interface Builder since UIScrollView.contentSize won't bother to listen to your commands.

Related

Label in cell positioned in the very upper-left corner?

It's very odd - my cell labels are looking something like this:
However my constraints are set as such:
If I remove the constraints completely, then it's working. But I tested on multiple platforms and on both the simulator and an actual device. I've tried multiple combinations of constraints, none of which seem to work. This hasn't happened to me before, albeit I haven't done much iOS programming in a while. Is there something obvious I'm doing wrong or new in XCode 9?
Edit: I was able to fix by deleting and adding back a new UITableViewController and recreating it, but it's very odd and I'm wondering why this could be in the first place.
Check the custom class for your Content View, one level below your cell. If the Content View is a subclass of UITableCellView instead of UIView, you'll see this behavior. Unless you're sure you want to create a custom class for the Content View versus the cell itself, make sure not to use a Custom Cell here, in which case your Custom Class for the ContentView will be set to UIView.
Apply this constraint on label

Why UITableView is only accepting touches on first row?

I'm using a custom UITableViewCell with an UIControl and a few UILabels in my UITableView and everything works fine only if the UITableView takes up the whole screen. I'm using a xib file for this.
The problem is that I need to resize the UITableView to take only the bottom half of the screen, and like this only the first row accepts touches. Also if I try to scroll by pushing up from lower cells it won't do it, but will only scroll if I hold the first row.
It happens on both iPad and iPhone, but it's particularly bad on the iPhone. It seems that only on the bottom half of the screen the scrolling doesn't work.
I've already checked all views, and there is none above the UITableView, I've checked all sizes, I've googled and searched on Stackoverflow, but I couldn't find anything similar to my problem.
What else do I need to be checking? Any thoughts on this?
The problem was that I had a custom Marquee UILabel, allocated and initialized via code and not via xib file, at the bottom of the screen and I was using the iPad frame instead of the iPhone one, so it was huge, being placed above the UITableView, consequently blocking it and preventing touch events.
As I was so focused on the xib file I totally forgot that I had setup this custom Marquee UILabel via code.
I thank Ethan Holshouser and Helium3 for all helpful comments above and the Reveal App suggested by Helium3 helped me greatly visualizing the views hierarchy to solve the problem.

When moving a subview around, how do I keep a subview of it in the same place in its superview?

That's a very convoluted title. Sorry.
Basically, I have a UIView that I've attached to a UITableViewCell so I can slide the cell around, or at least create the tric-- illusion of it. Within that UIView I have a UIImageView. I want to keep this UIImageView static relative to the view controller. So basically when I slide the cell around, I want everything about the cell to slide around with my finger (I have this done) EXCEPT the UIImageView. I want it to seem to the user like it's staying in one place -- which means to the cell's superview (the view controller's view) it's staying in one place.
What would be the easiest way to build this? I'm sorry I don't have code to share, I'm just trying to build this from a conceptual level first. My UIView on the UITableViewCell is slid with a UIPanGestureRecognizer and moving the UIView's frame if that helps.
Would I have to move it in the opposite direction of the UIView when it moves (say it moves one forward in x, move it one back in x?) or is there a way where I can just say "lock your position relative to your super-superview"?
I've had the same problem before.. what I did was simply not add the UIImageView as a subview to the UITableViewCell, and instead attach it to the parent of the UITableViewCell.. that way whatever happens to the UITableViewCell frame properties (ie size or origin) won't impact your UIImageView..
you may wonder: well one of the reasons I attach the UIImageView as a subview to the tableCell is b/c it's related to it in many different ways.. The response to that is that you can associate an object with another through objc_setAssociatedObject
If you come from web dev background, you can think of this discussion as the difference between position:absolute and position:relative discussion.
Initially I tried to do what you had in mind, basically moving them in opposite directions etc.. I just think my solution is a lot simpler to do.
abood was close, but close, but if you simply make the imageview a subview of the cell itself instead of the UIView I added over the cell, they operate independently. So contrary to the first line, adding it as a subview of UITableViewCell worked perfectly and didn't have any of the issues outlined. Works perfectly now.

UITableViewCell incorrect X positions

I've been searching through here and googling like crazy for a possible solution to this problem. Thus far I'm turning up exactly nothing that actually fixes it so I'm hoping someone can help.
I'm working on the UI for a iPad app. I'm doing it using interface builder. I worked with storyboards briefly but I don't like them all that much so I'm sticking with IB for now. Unfortunately I'm not very experienced with the workings of IOS Ui but it's been going relatively smoothly so far. In my app, I have a view controller, which holds a view containing a pair of sub views. One subview contains a rather windows like header bar (i like the look). The second contains a UITableView. The UITableView is set up properly as far as I can tell, and feeds it's info from a data source using custom UITableViewCells. The UITableView is set to grouped though currently there is only one section. The table is in edit mode by default because I want the user to be able to add new items and use the VC as a selection dialog. The view controller is presented (rather than pushed) using UIModalPresentationFormSheet (again, because I like the view) but I don't know that has any bearing on the problem. The cell border is flush with the X origin, the only reason the text isn't currently starting there is because I went into my cell and move the label over, leaving a gap between the edge of the cell and the label containing my text.
The Offending View http://bit.ly/144cbjT
The Problem: The UITableViewCells, for some reason are positioning themselves at X: 0. This puts them outside the border drawn on the UITablewView when you set it to grouped style. I could probably just turn off the border and get away with it, but I like the look so i want to keep it. I've tried messing around with constraints and anchor points on the cells, the content of the cells, the table itself, the view... I've tried simply moving my cell's labels over a bit. I've also had clipping subviews turned on and off. I've made sure the controls are being loaded properly from the XIB. I've made sure everything is added as a subview where needed. I've made sure I've tried everything I could think of short of setting the cell's X position in code. But since I'm not sure how to tell where the border is, I'd rather have the tableview or the cell do the work itself.
The question: How do I fix this? The selection accessory should be outside the grouping box. The text should be inside, not bleeding out onto the background like it is.I believe the content of the cell should be displayed inside the border within the yellow area.
The odd thing is, this is my fifth or sixth table in this app and I've been doing them all basically the same. Thus far this is the only one I've had trouble with.
Can anyone shed some light as to what's going on?
Thanks in advance
I think that to get this in code, you'd have to do something explicit, so the most likely candidate is a messed up IB file.
Since it doesn't cost anything, I'd just delete the tableView from the IB and then re-add it. If that doesn't work, try recreating the complete IB.
Hope that helps

UIScrollView unwanted scrolling after addSubview or changing frame

I have a UIScrollView filled with subviews, all is well when creating it and initially filling it.
But when I add a new subview that is positionned outside of the visible screen portion, or when I just resize an existing subview that is also outside of the visible screen portion, there is a subsequent 0.3s-long scroll animation (I can see it happening from my delegate) that seems to match the newly added/resized element.
Attempts:
pagingEnabled is always NO.
Setting scrollEnabled to NO during subview manipulations doesn't help.
Doing a setContentOffset:animated:NO after subview manipulations doesn't prevent the animation.
One single giant subview with all my subviews in it doesn't help.
My current workaround is to initially set the frame to fit inside the visible screen portion, or doing resizing work inside another superview, but it feels dirty, and won't handle all situations...
Is there a way to prevent this automatic scrolling animation when programmatically manipulating subviews?
Xcode 4.3, iOS SDK for 5.1.
I too discovered this problem and found this solution http://www.iphonedevsdk.com/forum/iphone-sdk-development/94288-disabling-uiscrollview-autoscroll.html
It involves subclassing the UIScrollView and entering no code in the following method.
- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated {
}
Like the guy says on the link I've found it works and no problems so far. Hope it works for you.
I had this problem because I set the content size of the scroll view prior to adding the subview.
As soon as I change the code so that the content size of the scroll view was set after adding the subview the problem went away.

Resources