How to make framework with storyboard and UIViewControllers - ios

I made an app with two View Controllers and storyboard to them. At all everything works perfectly but at all I must to create framework from this objects.
The structure looks like this:
Framework:
FirstViewController.swift
SecondViewController.swift
Storyboard.storyboard
AppExample:
AppDelegate.swift
I want to present in AppDelegate first View Controller. After presented it user will make some stuff and after push the button SecondViewController will be pushed on the screen. This second View Controller could be dismiss by the user.
The problem is:
I move all swift files to the Framework folder with right target membership.
After init the First ViewController I have blank screen
I do not know how to connect storyboard with the views
This two UIView Controllers are only the tool that will be added to the few apps later. The point is that developer can put first View Controller wherever he want and after that he will have the answer from Second View Controller.
I will be glad for help.

Related

how is view controller connected with App Delegate

I was trying to understand the flow of this app: https://github.com/JoelMarcey/iOS-2048
but I am not sure how this app works (absolute beginner)
So we have main.m which happens to be a starting point of the app?
https://github.com/JoelMarcey/iOS-2048/blob/master/NumberTileGame/NumberTileGame/main.m
main.m imports AppDelegate.h
https://github.com/JoelMarcey/iOS-2048/blob/master/NumberTileGame/NumberTileGame/F3HAppDelegate.h
AppDelegate.m does not import ViewController? So how does this App show initial screen and screen thereafter?
Shouldn't there be some code in AppDelegate.m? Can someone please explain me the code?
Also, how do I see Main_iPhone.storyboard in my project and not in repo online?
If you look in the NumberTileGame-Info.plist file, you'll see that there's a reference to a Storyboard. A storyboard is a file that the system uses to load UI elements such as view controllers, including (sometimes) the connections between the controllers.
In this app's case, the storyboard loads F3HViewController as the initial view controller. That's why you don't see a reference to the controller in the app delegate. Regarding your question of code in the app delegate, it's not necessary to have a bunch of code in the app delegate -- it's an architecture decision that determines what code goes in view controllers, the app delegate, etc.
Regarding your comment about the storyboard, the storyboard is in the repo -- it's in Base.lproj.
AppDelegate.m does not import ViewController? So how does this App show initial screen and screen thereafter?
This is a storyboard-based app. The Info.plist specifies the storyboard to use, and that storyboard specifies the initial scene, which is basically a graph of objects including a view controller and its view hierarchy.
If you open the storyboard file, you'll see an arrow pointing to the first scene, which will likely have an instance of F3HViewController. I haven't actually downloaded the project, but that class seems like the obvious candidate since it only has a -playGameButtonTapped action that presumably is connected to a "Play" button. That action then instantiates and presents the next view controller, F3HNumberTileGameViewController, and gameplay begins.
Shouldn't there be some code in AppDelegate.m? Can someone please explain me the code?
Only if you want to customize what the application does. In this case the developer doesn't seem to want that.
Also, how do I see Main_iPhone.storyboard in my project and not in repo online?
It's in the Base.lproj subdirectory.

UIStoryboard segue fail

I created a simple Show segue by dragging from a UIButton to another UIViewController in storyboard view. It's configured as all of my other VCs and has a custom class that is specified, with linked IBOutlets and IBActions (which appear to link up when I hover on them).
NOTE: When I first created it, there was no view controller class specified. I've recreated it several times since then, but I'm wondering if some value is cached that's pointing to a default view controller. Although I get print lines from the correct view did load method...
For some reason, when I run the app and click the button it links to a black, empty view controller. The navbar pops up without any back button (these views are embedded in UINavigationController).
After looking up other posts about this kind of issue, I've deleted and recreated the segue, cleaned my build folder and restarted Xcode. There's no source code involved in this, just storyboard configuration. Any help on next steps?
According to the code shown in your screen shot, the problem would be that NodeEnrollmentViewController is a subclass of UINavigationController. That's wrong. It should be a subclass of UIViewController.
You cannot (and do not need to) segue from a view controller within a navigation controller to a navigation controller.

Can you define a Segue in the storyboard to self?

I have an app that represents a folder structure. I have a UITableViewController for the folders and files listing, and a UIViewController for the Documents.
I want to be able to recursively navigate through the folder structure, so I want to reuse the Folder UITableView multiple times while I let the user drill down a folder structure.
Is there a way to draw a segue from the UITableViewController to self so when I select a folder I present another instance of the view, but with the content of the subfolder?
I did this in previous versions of Xcode, but I cannot figure this out on Xcode 9.
You can use Storyboard Reference and Storyboard ID of ViewController in Interface Builder
Screenshot
Yes you can do it. Add a hidden button in view controller and drag & drop segue self view controller.
I've never created a segue link to the same view controller, but based on Halil's answer above, it sounds like it's possible.
Rather than messing with hidden buttons, though, why don't you give your scene a storyboard identifier, and then instantiate and push/present your view controller through code? You could put your logic in the table view's tableView(_:didSelectRowAt:) method.

Mapview in tabbed application in iOS

I would like to ask something, because as a beginner I do not have any idea anymore
how it could work.
First of all I made a new project, a single view one and added a simple map view.
This worked very well (following a tutorial of course)
Now I tried to add this simple map view to my inital project, which is a tabbed based on with navigation controller.
In this tabbed application I already added two more views with view controllers, and I called them thirdview Controller and forthview controller. The vc's I gave the class thirdview and forthview controller.
So, now I wanted to make the mapview on the thirdview. I did exactly what I did in my "trial project" but it is not working. Well, when I run the simulator I see a map. But it does not show the location as I have specified it inn the thirdview controller.m
Because it was working in the singleview project, I guess I have something to add or to connect in my inital tabbed application?
I would be greatful for any help on this
Thanks a lot
What you have there, as I can see from what you say, is a very simple and litle forget made by everyone who begins with xCode :)
Try to link your viewControllers and your map (in the xib or Storyboard) to your file's owner' view and delegate.
by default, these aren't linked. Just right click on it and drag your View and delegate to your file's owner.
Also, be sure that each of your viewControllers' classes are really thirdview and forthview in the properties (don't be confused with xib identifier!)
Hope this helped you! Feel free to ask if anything is missing :)

What's the proper way to use storyboards View Controllers and scene in iOS application?

I have been working on an iOS application for sometime now, and I think I am not using the View Controllers I have created properly with the storyboard file / scenes I have created for my application.
As it stands, I have two storyboard files, one for the iPhone, and another for the iPad. In the AppDelegate implementation file there is a method called,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
I have been loading a ViewController from within this method to start the load process for my application.
Since I have two storyboard files now, I sourced some conditional code to load a specific storyboard file based on the device that is running the application.
What is the proper way to load the storyboard file?
After I load the story board file do I initialize the root view controller?
Once my root view controller is loaded should it load the elements specified in the root scene?
If I choose to load another scene from the root scene by clicking on a button in the root scene should I dismiss the root scene, and load the new scene, or is the new scene a subclass of the parent scene? What is the proper way to transition between scenes?
Basically I have a separate view controller for every scene in my application, and I have specified a view controller associated with each scene in IB.
Right now I have a button that can be pressed from the beginning / root scene to load another scene which is associated with another view controller. In this new scene I have a done button which segues back to the root view controller.
If I were click these two buttons repeatedly by clicking on the buttons over and over, am I creating new objects of my view controllers or I am reusing the objects that were already created?
I know this is more than one question but I am trying to get a good grasp on view lifecycles, and how view controllers relate to scenes, and the proper way to load the first view controller, which should load the first scene in an application I presume.
What is the proper way to load the storyboard file?
Click on your project in the class navigator. It is the uppermost thing you can click in there, and it has the name of your application on it. Some config files will open right where your source code used to be, and you need to find the one where you can specify a storyboard for different devices. I think it is the second tab from the left, but i cannot check that right now. You just specify a storyboard to use for iphones and a storyboard to use for ipads, and youll be fine.
EDIT: you also need to specify an initailView for both storyboard files. This can be done by simply opening the identity inspector (i think) in storyboards with the view in question selected and checking the box next to "is initial View". Try all four inspectors if my memory fails me. It'll be there, i promise ;)
What is the proper way to transition between scenes?
in most cases, you will use a segue. those thigs are new in storyboard, and they are the bomb. Theres a method you can implement called
-(void)prepareForSegue:(UIStoryboardSegue *) sender:(id)sender
where you can check for the identifier of the segue and then manipulate the destinationViewController-properties directly. Heres a good tutorial:
http://www.appcoda.com/storyboards-ios-tutorial-pass-data-between-view-controller-with-segue/
If you cant use a segue, however, you will need a rootViewController for anything that displays more than a modal view. Basically, rootViewControllers manage a stack of views, and its not your business how they do it. Depending on your UI you might need a NavigationViewController or a TabBarViewController, just google for both and see what suits you best.
Feel free to ask any questions you might have, ill be glad to help you.
Have fun

Resources