UIWebView IBOutlet Connection issue - ios

So I'm going to try to explain my issue as best I can.
I have 2 View Controllers on a Storyboard. One is the "main" VC and the second is a "EULA" VC.
The main view controller has a UIWebView which loads the primary UI and works fine. This controller uses code to perform a Modal segue to the EULA VC which is created in the interface builder. This also works fine.
Now here lies my problem. The EULA view controller also has a UIWebView on it but I can't seem to connect this view controller to any connection by means of CTRL + drag. The "main" UIWebView is connected to ViewController.h
This is how I create my connection with CTRL + drag:
My question is why am I able to connect the first UIWebView on the Main view controller but not the other UIWebView on the EULA view controller? What am I missing?

Have you set up the EULAViewController.h as the custom class for the ViewController in Interface builder? Select the UIViewContoller in Interface Builder and in the third tab make sure the class is correct. Here is a screenshot explaining what I am saying:
Also make sure you have selected the correct file in the right pane, both red boxes should show the name of your custom UIViewController subclass:

I am think this is a bug in XCode or what. But this is very rare issue. I also got this issue sometime. So posting a solution which can make you little nervous to implement. But it works for me sometimes. You can try it . -
Just create a new UIViewController subclass in your project and name it something slightly different than the first. Then, copy/paste all code from old non-working UIViewController into the new UIViewController subclass (.h and .m) and change all relevant symbols according to the new UIViewController subclass name. After doing this I found everything worked as normal in terms of trying to control-drag wiring the buttons.
Happy coding. :)

Recreating the class files, renaming the view to something else then back to EULAViewController AND following these steps I was able to fix the issue.
Close the project you are working on with.
Delete the【DerivedData】folder of you project. (This folder may
inside your project's folder, or inside
~/Library/Developer/XCode/DerivedData/(your project)/ ) or somewhere
else that were setup by you.
restart you project.

Related

Can't connect UI to ViewController using Swift 2.0 in Xcode 7.1

So I am trying to connect some UI objects to my ViewController, but it doesn't seem like they want to connect to each other. Maybe this is something to do with having two ViewControllers?
Before you ask, I already tried to remove the other ViewController and worked to no avail.
Here is a video of my issue in progress.
https://youtu.be/ha_6v92yJ6E
Probably your view controller class is not properly set. You need to go to storyboard select top yellow tab then go to Utilities on right then select Identity Inspector tab
Set your controller class name here for eg: ViewController in above image.
Hope this might help.

View Controller Loads Twice - How Do I Fix It?

The Problem Cause
When I added a new Swift class file to my iOS project, I decided I was indecisive and renamed it, deleted it, and created a new file. I think that I was actually so indecisive that I renamed it a few times.
The Problem
Now that viewController loads twice. I can literally see the transition happen twice and, during testing, I can see my viewDidLoad run twice in my console.
Common Fix
I know the first solution to check for is duplicate segues / segue calls. Check your document outline to see if there's more than one segue. In my case, it is definitely not a segue problem in the storyboard or the viewController.
My Uncommon Situation
I found someone who had the same load-twice problem and it was because of the rename:
They said it was the renaming I did that is at the root of my problem and it is not easy to fix because the duplication is now in my XML file. But where is this XML file and how do I edit it to erase the original instance of the class? I have no idea.
So how do I solve this loads-twice issue? I just want my viewController to have a normal segue!
Resolved my issue!
If you messed around with a class's name (or it's file name) and have the same "loads twice" issue that I was having, you might be having a hard time solving it. The only suggested solutions I found said to create a new project from scratch and copy stuff over. BUT, instead...
Here's the simplest solution ever:
Rename the class of the viewController that's loading twice! Don't worry about the file, but the view controller class within it. Your XML file probably has duplicates of the original class name, but rename your class to something entirely new and you should be okay.
Delete Segue and declare it the right way.
I faced the same problem. The reason was I ctrl dragged from the TableViewCell to target ViewController.
So I deleted the segue simply by clicking on it and pressing the delete key on my keyboard.
Then ctrl dragged from the ViewContoller of the first view to the second ViewController.
The wrong way to declare Segue
The Right way to declare Segue
It happened to me also. My case was for Creating a segue from my UIButton and performing it from source code.
If it matches to your case then just create the segue direct from the ViewController to your desired ViewController.
The perform the segue. It works.
I recently created the same problem where my view was loading twice. I have a tabbed app. The view controllers for each tab uses a Content View with a segue. For some reason I had set the Custom Class for the View Controller and the Content View Controller to the same custom class.
I don't know how both got set, probably something I did and forgot. If you are seeing a view controller load twice and the above answers didn't help, check to see if you have the parent view and the content view using the same custom class.

Can't drag and drop item from storyboard to viewcontroller in xcode

I started working with xcode a few days ago, and today I tried to connect a textview from the main storyboard to the viewcontroller, but I figured out that its not working.
I am able to ctrl+click to drag the item, but unable to place it in both viewcontroller.h and .m. I double checked that its viewcontroller and not UIViewcontroller, so this is not the case.
I'm using a Yosemite 10.10 mac.
Any kind of help would be appreciated.
Select the ViewController in storyboard and change the name of the ViewController to the name in the .h or .m file and then try ctrl+click and drag
For beginners -- > make sure you have kept the "Ctrl" key pressed down while dragging and dropping onto the code. This can be easily missed.
For me, the solution was to click on the "View" item in the dropdown menu that shows all the subviews for the controller.
Simply clicking on the controller image on the storyboard does not appear to properly "select" the controller for drag and drop abilities, the base view must be selected.
Make sure you're in Assistant Editor Mode (When code and layout editor are side-by-side).
From Apple:
With Interface Builder open in the standard editor pane, select the
control you want to configure, and click the Assistant Editor button
() in the workspace toolbar.
The assistant editor opens your object’s implementation file.
Control-drag from the control in Interface Builder to the
implementation file. (In the screenshot, the assistant editor displays
the implementation file of the view controller for the Warrior
button.) Xcode indicates where you can insert an action method in your
code.
For anyone who is new to XCode this picture might help more:
Select the item in Main.storyboard from the right pane and then set the class for the view in the right pane. Now you can ctrl + drag into your class
After trying all of the other answers, what finally fixed this issue for me is simply restarting Xcode and I was able to see the blue line that indicates where I can place my action method...
Note that dragging to any point in your code doesn't necessarily work. If you've been unable to drag to create the connection in one spot of your code, try dragging to another spot. For me, I was trying to drag to add a connection in the middle of a function which didn't work. Dragging to the beginning line of a function or in between functions did work.
Note: I'm on Xcode 9.1
Try selecting your view in the storyboard and clicking on the identity inspector on the right side in class. Enter your view controller name and then drag and drop the item from the storyboard to the view controller.
Hope it helps.
I had to both rename the class (from ViewController to ViewController2) of the ViewController.swift file and change the Custom Class (from ViewController to ViewController2) of the Main Storyboard's View Controller to make Ctrl-Drag-and-drop work again.
Renaming back to ViewController from ViewController 2 in ViewController.swift and Main Storyboard did not thwart the Ctrl-Drag-and-drop, it remained working afterward as well.
Hey I think you are not connected your storyboard viewController with your viewController class. check screen shot which "suhit" uploaded in his answer.
I would like to tell you something more than it.
When ever you need to connect any storyboard object with class.
first go to utility panel (right side) and then set class there.
after that you can connect your controls with class
I hope it will help you.
Check that the names on Viewcontroller identity inspector and the .h, .m files are the same. That worked for me
I'm using Xcode 9.2 I had my ViewControlled refactored into sections using the "extension" keyword. It appears you can't control drag into an extension of a ViewController. If you go up to the top part that is in the class definition, control dragging works fine (assuming you did the other things in this thread about making sure the right class is associated with the view controller.
I had same problem, I realised I selected wrong story board. If you made app with default settings you will get two story boards (Main and Launch Screen). Labels on Launch screen story board cannot drag drop.
Make sure that the item in question is connected to the file in which you want to control drag it to (specify the class in the identity inspector)

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 :)

iOS: UIViewController is Not Being Pushed Problem

I'm working on a new app where there is a "main" UIViewController with some UIButtons and once the user clicks on the buttons, the application is navigating to another UIViewController.
For some reason, the UIViewControllers are not opened, when you click on the button nothing happens. Several points that anyone who tries to help should be aware of
I'm using code and interface that are very similar to another app that I had created and is working fine (I triple checked the code, and it's the same in the area that makes the UIViewControllers navigation)
I triple checked the Interface Builder items and their connection to the IBOutlet us fine (view is connected to view, File's Owner is set correctly, etc...)
I inserted NSLogs to the UIViewController that is not being pushed and I can see that initWithNibName is being called, but viewDidLoad is not being called.
I'm using basic-simple code to create and push the UIViewController: alloc+initWithNibName and then presentModalViewController or pushViewController (none of them work) and as I said, in another app with the same mechanism it works fine.
I don't know where to look! Maybe I unchecked by mistake some "Enable" button in Interface Builder or something like that.
Did anyone encounter something like that or may have some new thought regarding to where I should be looking?
Hmm, strange. Things i can come up with now are: dit you call [super ] in your viewDidLoad?
Is it stacked behind another view? Run instruments to see if all the things on the pushed view are allocated, so you know if the whole view is loaded. And you use a navigation controller? than you use pushViewController. When you are not and want a model you use presentmodalviewcontroller.

Resources