Connecting file owner to app delegate - iphone

At some point I deleted the Object to my appdelegate file for some reason from the XIB. I added a new object, and selected MyAppNameDelegate as the class. However, it's not connected to file owner, and I dont seem to get the option when right clicking and dragging. I think this is causing me some runtime issues. Any ideas?

If you are referring to your MainMenu, the the file's owner is an object of type NSApplication.
In IB, you should select your file's owner, access it's 'delegate' outlet and drag it (as to draw a line) to your app delegate. This will restore the connection.
Check also that your file's owner has got the NSApplication class type. Maybe it got changed somehow.

I had this same problem. I found a lot of half-answers on different threads, so I decided to put them together here.
Drag an NSObject instance from the Objects palette to the area below "Objects" where the objects for your xib are listed (click on the triangle at the lower left if you can't see it) for MainWindow.xib. The object should show up as a solid orange box.
Select this newly-created NSObject, and change its class to the name of your new App Delegate (whatever the file name is without the .h or .m), using the Identity Inspector. This should be an option in the pop-out list.
Control-drag from the File's Owner to the new object, which should not be displayed as " App Delegate", and select delegate.
You will also probably have to reconnect the Window (and possible other views) to your new delegate. Do this by dragging from the App Delegate to the Window and selecting window.
Hope this helps.

This was driving me nuts also.
I marked +1 above, the answer does in fact help, the answer is cryptic, so this will help explain in finer detail how to get a delegate or another connection that won't link directly into the file using the "Assistant Editor" view.
right click = control key + left click.!
IN XCode 4. Select any of your XIB files. Say for a UIScrollView you added, you want to set the Delegate for it. Well unlike the prior IB where you just open up connections inspector, and drag a connection to the file. Its actually just the same here. BUT a difference.
(NOTE:The dock is panel 2 from the left. Only with a XIB open)
Open up the Dock > http://developer.apple.com/LIBRARY/IOS/#documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/InterfaceBuilder/InterfaceBuilder.html
There is a small triangle arrow there at the bottom of the Dock.
At the very top of the Dock is "Files Owner", without the dock opened, it is the white box with orange trim.
Select the view or what ever needs delegate access to the File (UISegmentControl drove me nuts on this too), right click and drag a connection on "New Referencing outlet" to the Docks "Files Owner", and a list will pop up.
Like wise, you can right click on the "Files Owner" and remove connections easily there, or make new ones.

Related

How can I find the file my storyboard outlet connects to?

This may be a silly question.
I know I can easily go to my storyboard from my outlet e.g.
Is there an easy way to do the reverse? I'd like to go from my storyboard element to my swift file, specifically the line of code where the outlet is declared.
I'm not aware of any shortcut link back to the declaration of an outlet. A couple of alternatives are:
Use the Assistant Editor (it's the middle button below with the two overlapping rings) while you have a View Controller or an element within it selected in a storyboard. It will load up the accompanying class in a panel beside the storyboard view.
Select the View Controller itself out of the hierarchy, go to the Identity Inspector on the right, and tap the little gray circle icon with a white arrow in it beside the class name. That will take you to the class file in the main editor.
Those are the only two methods I know of for getting to the associated class.
Select the element and then click "Show the Assistant editor" at the top right. It will take you to the correct class, but not to the exact line it is declared on.
Select element:
Click "Show the Assistant editor":

How make connections with subclassed UIView

My project has a UIView located in a View Controller. The UIView has a subclass named AdminView. I want to add IBOutlets and IBActions on the subclass and connect them to controls on the UIView. I have found this is difficult to do with Xcode 8.2.1.
Image with IB and subclass set to AdminView
At first I selected the UIView in IB. I then clicked the Assistant Editor hoping it would bring up my subclass. I first set the jump bar for the Assistant Editor to Automatic Mode. It didn't bring up the correct subclass in Automatic Mode. So next I put the jump bar for the Assistant in Manual mode and tried to navigate to AdminView.swift. Sometimes I couldn't do that because the Manual jump bar only showed interfaces.
Image with IB and Assistant Editor, side by side
Why doesn't Automatic mode select the proper file?
When in manual mode, why does it sometimes show interfaces rather than my .swift files?
When it works properly, I was able to navigate to my AdminView.swift file. Then I tried to control-drag connections from the IB to the file. Xcode would not make those connections.
Why was it not able to make connections?
Next I selected the UIView in IB and opened the Connections Inspector. The connections inspector showed the controls that are inside the view. I then tried to drag from the dots to the right of each control to AdminView.swift. That did not work either.
Image with IB and Connections Inspector
Why did this not work?
Now for some good news. Next I went to AdminView.swift and added IBOutlets and IBActions for the objects in my UIView. I made sure to copy IBOutlets and IBActions from other parts of my project in order to make sure the syntax was correct. The I built the app. Dots appeared in the gutter next to the IBOutlets and IBActions I had just created. Then I put AdminView.swift in the Assistant Editor. Now I dragged (not control-dragged) from those dots to their respective controls in IB. Thankfully, this made the connections I needed.
Image with some Outlets and Actions manually added
Image with some connections
Why was this the only method that worked?
Does anyone know of any other methods besides this to make these connections?
Is there anything I can do differently to make the other two methods of making connections work?

Cannot connect .xib file after corresponding classes are already created

I'm using xCode 4.2, and after creating the .h and .m classes separately, I go and add a .xib file of the same name. So now I have:
ExampleClass.h
ExampleClass.m
ExampleClass.xib
However, the ExampleClass.xib won't connect to ANYTHING. I try dragging it to file's owner, to anything, and it won't connect. How do I go about doing this? The differences I see are that when creating all of them at the same time (.h, .m, and .xib), I see that when clicking on file's owner, it has "searchDisplayController" and "view" in the Outlets under the Connections Inspector. The one I created after the fact, ExampleClass.xib, has no "Outlets" section. I may be overlooking something, but I've tried restarting xCode, looking at other example code, etc... and I can't figure this out.
The first connection is in the Identity Inspector, which you can quickly access by pressing Option+Command+3. You must also set the File's Owner's view Property to the main view in the nib. The second step is often overlooked, and that results in a seemingly inexplicable crash.
In Interface Builder, show the utilities, beyond that show the show the identity inspector and assign the custom class.

Xcode issue - cannot connect button to object

I seem to be having an issue. The tutorial I am following from Apple's Dev Center says:
Control-drag a connection from the
Convert button to the
ConverterController instance in the
nib file window.
A black box will pop up similar to
the one we used to connect outlets.
Choose convert:.
Save the nib file.
I usually hold ctrl and drag the mouse from one object to another. However, when selecting a button from my User Interface and trying to drag to an Object in the xib window (this is all in the Interface Builder), the object will not highlight. It just won't let me do it!
Any ideas why this is happening?
you can use the "tree" map of all the objects in your nib file so it is easier to select one. this is helpful if they are on top of each other, hidden, or otherwise difficult to click directly. in xcode 4, there is a little triangle button along the bottom left of the nib view; if you click it, a sidebar opens with a text outline of all your nib's object. you can click the button in this list so it highlights, then control-drag to your file owner to attach it to a method you have written. the sidebar is also useful if you want to re-order objects in a view or subview, to make some on top of others.
Right click the file owner file a pop up will appear in front of you their you can see various action methods that you have in your project.
select a particular action method and then assign it to the appropriate button on which you want to call the appropriate function.

How to make a "view" Outlet show up in a ViewController nib?

I'm working on my first iPhone app and have been able to get most things done. There's one problem that I've run into a few times and I want to understand the issue better.
In XCode, if I go File->New File->UIViewController subclass and make sure that both UITableViewController subclass and With XIB for user interface are checked, then it creates a MyViewController.h, MyViewController.m, and MyViewController.xib.
When I look at this xib in Interface Builder, you can see that the File Owner has an Outlet called view that is already connected to the UITableView. No problem. This all makes sense and is great.
My issue comes when I've changed the type of my class (or done something else) and some how the "view" Outlet goes away. I get an error saying "view not showing up in file owner outlet".
My question is how do I then reconnect the UITableView as the "view" of the ViewController when the Outlet goes away? The only way I've been able to get it to work is to literally start over with a new xib/viewcontroller.
That "view" outlet should be coming from the parent class (in your case UITableViewController).
What do you mean by change type? If you are changing the name of your class, try using Edit > Refactor with the class name selected in Xcode.
In the "Document" window (cmnd + 0) - control + click on file's owner, a weird looking line thing will show up. drag the mouse over to your view and release. a little drop down will come up from which you can set the view to the File's Owner View outlet.
Typically the "view" outlet would be coming from the parent class (UITableViewController). If it's not showing up, then Interface Builder is not connected to your project than this could happen instead.
My problem was due to an edge case as described here: Interface Builder and Xcode integration not working