how to work with multiple viewcontroll and use the viewcontroll.h and m file - ios

I am new with xcode.
I used one viewcontroller and coded it in the viewcontriller.h and .m files.
My problem is when I add more viewcontrollers, I can't create more action from the new viewcontrollers to the basic files (viewcontroller.h and .m).
For example to right click and drag swipe recognizer from new viewcontrollers to the viewcontroller files (h&m files) in interface builder.

As my comment seems to be the answer, I'll add it as an answer:
I suspect you do want to set the class of the newly added view controllers in interface builder to the class of the view controller you want it to be.
Then, you can drag-connect like with the first one, xcode did set up for you initially.
Also, do remember to use different view controllers for different purposes (you might have to create another subclass of UIViewController).

Related

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.

Subclassing a View Controller

I have a single view aplicaition on xcode with several view controllers and xib files in it. I am trying to subclass a xib file's view controller called ViewControllerPg62 as a sub class of a view controller called ViewController. How can i do this?
Thanks in advance
Why are you working with XIB files? You should be using Storyboards.
I had to go back to an old project using XIBs to see how they worked.
In an XIB you should see an entry called "Placeholders", and under that, an item called "File's Owner." That represents the object that owns and manages the views in the XIB. Select that, and then display the Identity Inspector. There will be an entry at the top "Custom Class" where you can change the class that manages this view controller.
Before changing that, I suggest you create the source file for your view controller ("ViewController.swift", in your case.) Then when you change the class of the owning object, the XIB will create an instance of your custom class when that XIB is invoked.
The approach is quite similar for Storyboards, although it's a little more coherent.

What is the storyboard equivalent to an M file

So I have been using objective C and XIB files to do iOS programming for a while. I am starting now to learn storyboards and I am having a hard time figuring out how to write code for the storyboard. For example I am making a view where a user inputs info. Using my old style I would make a m, h, and a xib file. Edit the xib, link the elements to their definitions in the H file and make an iboutlet so that I can use it in the M file.
Now I have made a storyboard and added elements, how can I actually reference the elements in code, and where do I even put the code?
You create a subclass of the UIViewController, UIView, etc... Jus exactly as you would have done with a XIB. Then you set the class in the desired object in the storyboard just as you would have done with a xib...
Once the class is set you can link selectors etc as you would have done with a XIB file.
Now I have made a storyboard and added elements, how can I actually reference the elements in code, and where do I even put the code?
It's exactly the same as with .xib files. You can think of a single storyboard file as a collection of .xib files. A single .xib file typically contained a view controller of some kind and a view graph; when you instantiated the view controller, the view controller and its view graph were read out of the .xib and turned into objects. It's largely the same with storyboards -- you still have .m and .h files for your view controller class, and you still use IBOutlets to connect elements in the storyboard to properties or instance variables in your view controller.
The main thing that's different is that a storyboard allows you to specify the transitions between view controllers, so that you no longer have to write the code that creates a new view controller and transitions to it.

Create View Programmatically in Objective-C Xcode 5

How should I go about creating a View for the storyboard programmatically? I want to access the labels from the first ViewController object made(automatically to call the IBAction methods of VC). I know that this first object of VC is the one linked to the view in the storyboard(?) and I need to change a label form another file, besides VC. I'm pretty sure the only way to do so would be to access the VC object that is linked to the view, or create one and not go with the default one that is created. If not, how would I go about accessing the labels of the view from another file?
You don't create storyboard objects programmatically. A storyboard is very basically an XML file Xcode uses to call different view controllers. The biggest advantage of using storyboards over NIBs is you can layout transitions or segues, and the advantage of NIBs or storyboards over initiating view controllers by code is obviously the visual interface. So your question doesn't really make sense.
If you want to reference a particular view controller's label from your storyboard you need to create a pointer to that view controller first, but changing it programmatically doesn't make sense because that's what storyboard is for.
That said you may just need to go look for your class name in your view controller's Identity Inspector in storyboard and then edit your label programmatically through an IBOutlet property.

how do i generate view controller code defined in a storyboard

Here's what i'm doing :
I'm creating an xcode project using storyboards, defining all my screens by drag'n'dropping view controllers and views, but then I need to actually fill those screens with something.
So, i create uiviewcontroller subclasses files in my project, and fill the class name for every view controller in my storyboard. Then, I need to manually drag'n'drop every view elements into my view controller one by one, to generate properties.
I was wondering whether xcode offered the possibility to simply generate all the uiviewcontroller subclasses directly from the storyboard with all the outlets properties already set.
No.You only have to mention outlets and actions for all components which you want to use.If its automatically creates all outlets and properties and you cannot use "code conventions" for your application as you like.Sometimes your labels titles are static and you dont need outlets.so you have to connect each and every component.
http://oleb.net/blog/2011/06/creating-outlets-and-actions-via-drag-and-drop-in-xcode-4/

Resources