I know Apple don't recommend to Embed UITableView in UIScrollview.
So this is what I am trying to do:
I have a registration form with fields embedded in UIScrollview,
for some fields I create a drop menu by presenting UITableView, the problem is when the UITableView appears with my object the didSelectRowAtIndexPath not responding.
If there is another way it I will happy to hear, if not how can I fix it in the Current situation , thanks.
Don't add the table as a subview of the scroll view, add it as a subview of the superview of the scroll view (and, consider adding it into a container view which detects touches outside the table to dismiss it from the screen without any selection being made).
If your 'root' view for the controller is the scroll view, change your view hierarchy to use a plain view as the root and have the scroll view as a subview of that.
You may also want to use bringSubviewToFront: to ensure that the presentation is correct.
Related
I am having the following problem over and over again and I am looking for a clean solution to do this.
I have multiple views: a parent view (my rootView, controlled by my basic UIViewController) and a descendant view (a UICollectionViewCell in a UICollectionView which is a subview of my rootView).
The size of the UICollectionView is relative to the size of my rootView: in the UIViewController of the rootView, where I created the UICollectionView, I also created constraints (between the rootView and the UICollectionView) and added them to the rootView.
When a button is tapped in the UICollectionViewCell I want to change the size of the UICollectionView. Therefore I need to alter the constraints that are set on my rootView.
I have been told that accessing the constraints of the rootView via a downcast of the UIViewController and changing them this way is dirty, because having a view talk back to its (parent)controller is wrong.
How am I supposed to act in such a situation? How can I make the controller react to the view without the view talking to the controller? A point in the right direction would be great!
After your edits, it sounds like you only have one view controller in play here. In that case, life is good. The logic to manipulate the constraints that control your collection view belongs in the view controller.
You want to pass the button taps to your view controller, and have it handle resizing the collection view.
How are you handling button taps?
I have a UITableViewController inside a UINavigationController. I'm adding a "modal" subview to the tableView, which is a custom UIView when one of the rows is selected.
(It’s modal in spirit, not in the UIKit sense, since Apple doesn’t support modal views on iPhone, I’m adding it with a [self.view addSubview:customView] in my table view’s controller.)
I would like it to appear at the bottom of the screen and stay put there. I can get it to draw at the bottom, but once I scroll the table view, the view moves with it. Here are some illustrations:
Initial position (good):
Position after scrolling (bad):
I'm getting the bottom position by subtracting the height of all the chrome (navigation bar and status bar) as well as the height of the custom view from [UIScreen mainScreen].bounds.
How can I get the custom view to stay put? Should I constantly be adjusting its frame when the table view is being scrolled?
Your best and most flexible option is to switch to using a view controller with the table view as a subview so that you can change its frame and add sibling views. Then, when you want to add a modal you can run an animation to move the table view out of the way and slide the modal view in.
UITableViewController.view is an instance of UITableView. Means you added your custom view into a scroll view and that is why it scrolls. You can try to put your custom view into the tableFooterView property of the UITableView, which is the old school solution.
Personally I would create a container UIViewController and have UITableViewController be a sub viewController of it. Another sub viewController UIViewController or just a simple UIView could represent the footer.
I have a scrollview, I embed 3 controllers inside this scrollView in storyboard, and page between them horizontally.
content size of the scrollview is (scrollViewWith * numberOfControllers , scrollViewHeight)
scrollview appears and I am able to scroll horizontally thought the views, but the views don't detect any touch. (The controllers embedded have collectionViews inside them)
I implemented touchesBegin in one of the controllers, and it's never getting called.
Any idea what could cause the scrollview not to pass touches to subviews?
This isn't necessarily an answer to why touch events aren't making it to the collection views, but it sounds like you're reimplementing UIPageViewController with the transitionStyle set to .Scroll. Maybe consider using that instead?
when adding views to a controller through embedded segue, the view of the viewController is not added directly inside of the main view, but it's embedded in another container view before being added to the main view
ViewControllerView->EmbedView->EmbededViewControllerView
So I ended up removing them both, and manually add the view of the viewControllers to the scrollView
what kinds of view's you have inside every page of the UIScrollView?
You can add anything there, for example a UICollectionView, and the only way to prevent to not pass touches inside is having the UIScrollView set as:
self.scrollView.userInteractionEnabled = NO;
I want to create layout similar to default Weather App in iOS. My view controller has UIView at top and UITableView below it. I want to resize dynamically top view while scrolling table view. I made view controller delegate of table view so I can resize top view while
scrollViewDidScroll(scrollView: UIScrollView)
is called.
The problem is that I want to disable scrolling of table view while resizing top view. Any ides? Or maybe my approach to this layout is wrong and I should use another one?
I also faced same problem as per mine problem, I used my UIView as a header of table view and used the AutoLayout in my View and if you want to disable the scrolling of your table view you can simply use a block for completion of your view resizing and you can disable scrolling of your table until your block will not give completion. Hope this solution will be helpful for you.
I have a UIViewController in storyboard that will be a sliding up menu. I want to place it in a UITableView. If I place it as subview of UITableView and prevent it from scrolling, it gets the look I want, with one problem, the section headers of tableview scroll above subview.
Now, in order to prevent this behavior, I could reduce tableview frame, but it doesn't work because my subview is inside that same frame, right?
So , if that is true, what is the best way to achieve this? Place both screens inside a third UIViewController?
Don't try to put other views inside a table view. Bad news.
If your table view is managed by a UITableViewController then that's really all you can have in the table view (unless your views are inside cells, or in headers or footers.)
If you ARE using table view controllers to manage your table view(s), I suggest you create a container view on the view controller that needs to contain the table view, then control-drag an embed segue to the table view controller. That way the table view controller becomes a child view controller of the main VC, and you can put other view elements on the screen to your heart's content.