Pushing a ViewController Through a UIScrollView - ios

I have a custom uiscrollview class that has certain views and buttons. When I press a button in this custom scrollview, I want to present a new viewcontroller. Since this scroll view is inside of a view controller, and the custom class doesn't have the authority to push view controllers like a navigation controller, how do I push a new view controller through this uiscrollview class without throwing an error? Whenever I create a new navigationcontroller and an instance of the viewcontroller that I want inside of the method for when the button is pressed, and I present that viewcontroller, I get an error. Also, all of this is programatic and dynamic, not though storyboard. Thanks.

The scrollView must be inside a viewController.
The best way to accomplish your scenario is to put the viewController that contains the scroller inside a navigationController, Then you can push to wharever you want.
Hope this may help

You can try to instantiate viewController through the storyboard, or directly from class, after that present it as a modal view controller from your source UIViewController like this
presentViewController:animated:
This possible leads to animation issues, that could be solved implementing your own animation

Related

Is there a way to set the back button item image in every view controller of a navigation controller by subclassing the navigation controller?

I want every view controller in my navigation controller to have a custom back button. So far I've been setting it in viewDidLoad of every view controller, but that feels needlessly repetitive.
I tried subclassing UINavigationController and in the initializers setting navigationItem.leftBarButtonItem to the custom view. However it never shows up.
How would I accomplish this? Is it possible to use a subclass of UINavigationController to set the custom back button?

iOS custom view across all view controllers

I would like to have custom view set in one screen and have it across all view controllers in my application.
I find solution with using Container view. So I create RootViewController and I give it Container view and set my original MainViewController as embed in container. I added view to RootViewController and in first view controller (MainViewController) it looks good.
The problem is when I go to another view controller by Push segue. New view controllers covers whole screen (which is okay) and covers custom view too. I was thinking that it could help if I add Navigation Controller with root MainViewController and this navigation controller would be embed in RootViewController but the result is same. I set Navigation bar as hidden (same for status bar) because I want to be hidden.
So where could be problem? Or how would you add custom view to all screens? This custom view should work as global (I am using NSTimer and counting time) so I solution with inheritance isn't for me.
You can use application window and add this custom view as subview whenever required. I have used it in one of my app to show notifications (if there area any) and it works great.
Get handle to Application Window and add subview to it. Custom view can be created from a singleton class or App delegate.
You could try it the other way round. Make a view which will never change inside your root view controller and a container view and just change the content of the container view depending what u want to display next to your unchanging view.

Cannot see controlls of presented view that I dragged on stroyboard after calling presentModalViewController

I am a newbie in iOS developing. I am trying to accomplish a sample from a book, but I use storyboard instead of xib. I added some buttons to one of the view and assigned a viewcontroller to it. I tried to call presentModalViewController to show the view in a action, but it seems nothing on the presented view. I add some code in viewdidload, and it works. But why can I see the buttons that on storyboard?
You should be using performSegueWithIdentifier:sender:, rather than instantiating and presenting the view controller yourself. Only then is it deserialized from the storyboard.
If you really want to just use the storyboard as a holding area for your transitions, deserialize it with [self.storyboard instantiateViewControllerWithIdentifier:#"whatever"] and present the result. But that's not how storyboards are intended to work; the intent is to specify both the destination and the transition in your segue. That it's presented as a modal is just a part of the segue you define.
Think of it this way: A storyboard is not a direct replacement for a XIB. A XIB defines a single view controller's contents. A storyboard not only defines many view controllers and their contents, but how the view controllers interact with each other.

Can't create Segue from UIScrollView

I have a UIScrollView with my View, but I can't seem to create a seque push from this over to another controller.
I have successfully created a Seque from a UICollectionViewCell over to my destination controller but when I try and create one from the UIScrollView (in the StoryBoard) the blue connector will not see the destination controller as an option to create a segue too.
Any pointers would be much appreciated.
A push segue is only meant to be used with any type of button (ex. UIButton, UIBarButtonItem) or cell (UITableViewCell). Push segues are used to show another view controller over the current one. UIScrollView is only meant to scroll the content on the current view controller, just in case the content of the view controller exceed the screen size. I suggest you look at the Apple UIScrollView Class Reference page here to get a better understanding of UIScrollView
Push segues don't have to be connected from individual views like UIButtons or UITableViewCells. This is too limiting, because a button (for instance) can only connect to one segue. Try connecting them from the view controller itself, then you will be able to do as many as needed. I open the Document Outline, and drag from the View Controller at the top of the scene (the item having the yellow circle icon next to it) to the view controller on the Storyboard that I want to connect to.

Adding toolbar to a ViewController in storyboard

I'm using storyboard to create an iPad app. On the main view I have a toolbar and a bar button item, let's call it "show". Then I have dragged a table view controller into the storyboard. I have also added a subclass of UITableViewController to the files and made the class of the dragged table view controller to be that subclass. And I made a popover segue from the "show" button to the table view controller. It works fine, meaning that when "show" pressed I see the popover showing the correct data that I set in the table view. What I cannot seem to figure out is how to put a toolbar on top of the table view in the popover. I took a step back and used a UIViewController instead of UITableViewController and still cannot add a toolbar by dragging it to the view. Any help will be appreciated.
I ended up putting the TableViewController within a NavigationController and the latter in a PopoverController, all in the code, without using IB. I found this an easier solution to get the toolbar than anything else that might work.

Resources