Connecting code to UI in storyboard with multiple ViewControllers, Xcode - xcode

I have a storyboard project in Xcode. I have added an additional ViewController and dropped in a button, text box, etc. I can get from the initial to the secondary View Controller, but I cannot seem to be able to connect the button to the code. I've tried adding additional classes with XIBs and even from a blank adding in the XIBs. How do I connect the code I have written for a button to do work on the second View Controller?

If you have the button created on the storyboard. You have to make an
-(IBAction)clickButton...
in the .h and .m code files. You can easily connect the code to the button by dragging the line from the dot (in front of the code name) to the button.
If you have created the Button fully in code. You have to specify which code to be executed on click.
[self.buttonName addTarget:self action:#selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];

Here's the answer. You add new files to your project, and just for giggles, we'll call them NewViewController of the UIViewController class. Then, highlight the second view controller in the storyboard, choose identity inspector, and under Custom Class (at the top) you change the class to the name of the recently added NewViewController class. Now, all your code will connect to objects and so on. Thanks again for the help all and now I can rest in peace lol.

Related

How to find the editor for multi view controllers

I am very new to xcode, got stuck in finding the editor to modify the code when created multiple view controllers. Whenever I click on any of the view controllers, I only see same editor contents and cant move to the others for coding.
I searched the web and stackoverflow but could not find a clear guideline on how to manage the editors for multiple view contollers. I have attached a snapshot.
You don’t “find” code. You create it.
When you drag a view controller into the storyboard, it has the default class of UIViewController. It is up to you to make a new code file where you subclass UIViewController, and then to go back to your storyboard and change the view controller to that subclass in the Identity inspector.

Unable to find UIView in UIStoryboard

I'm using Xamarin.iOS in Windows. Everything is working fine except:
Sometime ago, I'd create a UIScrollView named MyScrollView inside an UIView at MyViewController.
Right now, I can use it normally programatically like:
MyScrollView.AddSubview(myButton);
The problem is:
I can't find the MyScrollView at the Storyboard Designer. I want to change some properties at the designer.
Question 1:
Is there a way to delete it and recreate since I can't find it at designer?
Question 2:
Is there a way to use a search at the .storyboard file?
EDIT:
Even if i right click over my UIView at the UIViewController, the Context menu doesn't shows the UIScrollView.
For some reason, It was created at the storyboard back-end, however it was just not showing at the Designer.
By adding the same component with the same name: MyControllerView it didn't duplicate, and assumed the original position.
Note: Special thanks to #Yuri S. It didn't solved by this answer, but i didn't know that i'm able to edit the storyboard via XML. So lesson learnt.

How to remove a navigation controller in storyboard?

I am following a simple swift tutorial that shows how to add a navigation controller to a viewcontroller in storyboards in xcode. This is done using Editor > Embed in > Navigation Controller
The problem is, once the navigation controller is embedded, it cannot be removed. The 'unembed' option is always greyed out. Removing the controller view from the storyboard results in an error. Even if the arrow indicating the first view is pointing to a simple empty view in exactly the same way as when you're starting a new project.
I would expect that there is still some code from the Navigation Controller lingering around somewhere, but how to pinpoint it?
I follow this step.
1) select navigation controller and delete connection.
2) make root view to your view controller
No...there is no source code, don't worry.
If your changes are hot then just Control-Z if not select navigation controller and press delete button.
"unembed" function is for unembedding the "stack" in stackView and not for "navigation controller" nor "tab bar controller"

can ttnavigator render a xib view in objective c?

I have followed the three20 ttnavigator example in order to make my own app, but I have seen than the view is created in controller, but I would like to make my view in a xib file and then render it from controller when openURLAction is fired, how is it posible?, thanks
I used to overwrite the initWithNibName to make my view in a xib file, navigator openURLAction is ok.

how can i add button in cell to open link

I want to make a button in cell that will open URL.
I try to make it as always, but it doesn't work.
I have custom cell with it .h/.m files and the tableView inside UIViewController. Where I have put code? and will this code work?
- (IBAction)site:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.vk.com"]];
}
Now you just have to connect the button target to this IBAction.
Go to Interface Builter, right click the files owner or app delegate, depends on how you have set it up. Then you should see the site IBAction, just drag it to the button and it should work.
Just add the code to the current view controller.

Resources