开发者

XCode and Interface Builder Problem: Cannot Connect UI Elements via IBOutlet

I might have messed up a setting or something when I made a few hot-key slips or mistakes. Not sure, but usually I was able to ctrl+click and drag to "File's Owner" and the outlets I made earlier would sho开发者_开发技巧w up appropriately.

Now it doesn't. Not sure how to fix this.


"...usually I was able to ctrl+click and drag to "File's Owner""

After adding additional IBOutlets to your controller class, you generally set them in Interface Builder by dragging from the controller object to the view item, rather than the other way around. (Here, a controller object is usually File's Owner, 'Application', or an instantiated custom controller object).

Less frequently, you might drag from the views themselves to the controller object(s) or to other view objects, to set class-specific IBOutlets like delegate, and/or dataSource, menu, formatter, etc. For example, NSTextField adds a delegate and a formatter IBOutlet to NSView's menu and nextKeyView IBOutlets.

So, you may want to double-check that you're dragging in the right direction for the object in question.

If you know you are dragging in the correct direction, and Interface Builder doesn't act like it normally should, there are a couple of things you might try.

First, if you added additional IBOutlets to your controller class and are trying to hook them up in Interface Builder, double-check that you actually specified the proper class for the view object you want. For example, to add a new IBOutlet, I'll sometimes copy an existing line, say IBOutlet NSTextField *textField;, and then paste it. I'd then change the name to tableView (with the intention of having the IBOutlet be connected to an NSTableView), but I'll forget to change the NSTextField to NSTableView. So when I would go to Interface Builder and try to "hook up" the IBOutlet by dragging from the controller class to the NSTableView, it wouldn't show a popup menu since a table view and text field are 2 different kind of objects.

Second, you might post the contents of your .h file. You might have forgotten a ;, or have otherwise created a possible situation which is causing the parsing of the .h file (by Xcode which then communicates the results to Interface Builder) to fail partway through. When that happens, it can prevent many of the IBOutlets etc. from showing up in IB. You might also try compiling your code as is to help ferret out where the problems lie. I've occasionally done this myself.


Not sure if there's a keyboard shortcut that would cause this behavior, but just to be certain you should check to make sure the outlets you expect to see appear in the Connections Inspector (right hand Utilities drawer). Keep in mind this panel changes as you select elements in your project.

If you're seeing the correct outlets in the inspector and still not getting the ctrl+click behavior you want, I'd try re-opening your project, restarting XCode, or finding+deleting the XCode prefs file.

Good luck!


I had the same problem:

  1. I added a TableViewController file in the Xcode project.
  2. I added the proper IBOutlet properties in the proper header file.
  3. I added a TableViewController in IB.
  4. I added controls to the TableView in IB.

But I could not attach the controls in IB to the outlets. The problem was that I didn't associate the TableViewController class in IB with the class I created in Xcode. The solution: Specify the Custom Class for the TableViewController in the Identity inspector in IB.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜