I added a custom view controller class with interface (.h), implementation (.m) files, and UI (.xib) to an existing project.
When I ctrl-click and drag between the nib and the interface, it will not place an outlet or IBAction when I drag, so I can't link a UI element to a property. Also, XCode does not bring up the corresponding interface file when I view the nib in assistant editor mode.
Note: I changed the name of the custom class. I changed the filename and the references to it in the source.
Make sure you click on file's owner on the left and then in the identity inspector on the right, put in the custom class. You should then be able to make connections.
Related
I am trying to implement a dropdown menu I found on github, it has pre-defined IBActions and IBOutlets. How do I connect theses outlets to the storyboard? Ctrl-drag is not working.
I believe my issue is that the file DropdownMenuController will not show up in the automatic section of files in the assistant editor. How would I add files?
Update:
The IBActions just aren't showing up anywhere. Here is an example:
All the outlets and actions that Xcode thinks exist
But here in the Objective-C files are IBActions that don't show up
First you have to set the right View Controller Sub class to the view controller in the interface builder. check the following setting
Now you open the Utilities panels and go to the connections inspectors, not the source files.
Select viewController in storyboard, open utility bar and in connection inspector you will find methods which are mark with IBActions
After drag and drop you will prompt like this
select vc first in storyboard like this
I have a XIB file inside of which there are some connections between some objects and the file's owner (a ViewController). I'm getting anything shown in the utilities sidebar that you can pop out from the sidebar in order to do some configuration stuff. It shows as "Not Applicable". I had created the XIB file along with the ViewController file (check marked the option in the New File sheet) so the file's owner was preconfigured to the ViewController by default. I have already made the connections and added the necessary IBAction selector for the UIControl stuff. Its just that whenever i select an object in the view frame, its config doesn't show up in the utilities. I have another XIB file hooked with some other view controller, and don't have the problem. What's up with Utilities sidebar????
I find restarting xCode often fixes this annoying bug.
I have a project that has the header and the implementaiton files and loads a plain old UITableViewController from the .m but I have no way of configuring the View (I would like to do stuff like ad buttons and text fields onto the view instead of just having a table), should I create a .xib file so that I can modify the view? (Reason I don't just start a new project is that the current project has a bunch of other stuff like OAUTH processes that kick off at the AppDelegate stage to log a user into a system - and I need this functionality). So my question how can I create a .xib from the existing .m .h files and then add other objects which I can then code for.
An answer from this similar question:
"Here's a more step-by-step way to associate your new UIViewController and .xib.
Select File's Owner under Placeholders on the left pane of IB. In the Property Inspector(right pane of IB), select the third tab and edit "Class" under "Custom Class" to be the name of your new UIViewController subclass.
Then ctrl-click or right-click on File's Owner in the left pane and draw a line to your top level View in the Objects portion of the left pane. Select the 'view' outlet and you're done.
You should now be able to set up other outlets and actions. You're ready to instantiate your view controller in code and use initWithNibName and your nib name to load it."
If it's a UITableViewController, simply create a new XIB file via Xcode (File -> New -> iOS -> UserInterface -> View) and then add set the file's owner to your subclassed UITableViewController.
You'll likely want to re-do how the user interface looks -- in terms of dropping objects like the table view and buttons or whatever else -- into the XIB's view. It'll certainly save a lot of time versus trying to debug programmatically creating and adding subviews and actions.
And once that's in place, you can then make IBOutlets and IBActions to your heart's content.
I keep trying to use CTRL-Drag from the uipickerview to the ViewController.h but its not creating the object definition in the header file. What do I do?
Make sure that in your xib/storyboard you have set the correct class in the identity inspector. From the drop-down menu, choose the correct subclass that you have created for your view.
I need to create a new xib file and want to use an existing xib to base my layout off of. What's the best way to create the new xib file? If it was Android I'd copy and paste the xml and then start tweaking but with the IB I don't have that option (right?).
I've tried two things so far, (1) copying and pasting the file in xCode but the option isn't there and (2) copying all the UI elements from the old xib and pasting them into a new blank xib. This copies all the UI objects, but doesn't maintain structure or spacing at all. What's the best way?
Just make a copy of NIB file, rename it and add to the same Xcode project. Change File Owner class in new nib if needed.
When I need to do this I convert the file to a .nib (shift click the file and delete .xib and add .nib) then you can see all the XML copy that. Then I make a new .xib and convert that to .nib and paste the XML then you can convert them both back to a .xib. You can also Right click the file and navigate to View As > Source Code
If Storyboard is used: Add a new UIViewController to the storyboard. Remove its main view so that the view controller is empty. Set the Class of the view controller (in the Identity Inspector) to that of your nib's File's Owner. Also make sure the .h and .m files are added to your project already.
Now open the nib, select the top-most view and press Cmd-C to copy it to the clipboard. Switch to the storyboard, select that new, empty view controller. Press Cmd-V to paste the contents of the nib into this view controller.
You may have to reconnect all the outlets and actions, but at least you don't have to do the layout again.