In XCode 3.2.x's Interface Builder this was simple enough, selecting the text cell displayed a small icon for the formatter that could be selected to configure the formatter in the attributes pane.
Now in XCode 4, the formatter icon is gone! If I drag an instance of NSTextField with an NSTextFormatter from the library OR drop and NSTextFormatter into an existing cell there is no way I can figure out to select the formatter to configure it!
Add to this the fact that Core Data entities UI prototype assistant was removed and I would say IB integration into XC4 is half baked at best!
Any luck with this anyone?
you can access the formatter from the jump bar at the top of the window. if you select the component you added the formatter to, click and hold and it will turn into a drop down menu. move to the sub menu and the formatter should show up where you can select it.
it seems that you can treat the whole ui like a cascading set of menus that way.
now removing the formatter, that's a different question...
... which after further looking revealed:
over on the left side of the IB window in xcode4 is a 'dock' containing the icons for file owner, first responder etc. this column is expandable, and when you do so will show a hierarchical view of the nib file. through which you can navigate like the finder.
also, see this article:
http://developer.apple.com/library/mac/#documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/InterfaceBuilder/InterfaceBuilder.html%23//apple_ref/doc/uid/TP40010215-CH6-SW3
Related
In older Xcode I have a little window where I could mark braces and band things to control how a NSView behaves when its parent is resized. In the new Xcode that is missing and the controls are doing whatever they feel like.
Is there any way to get this control back? (current version: Version 4.3.2 (4E2002))
Starting with Xcode 4.3 when you create a Cocoa application project, the xib file uses auto layout. Auto layout replaces the size inspector's autosizing mask.
If you want to use the autosizing mask, the solution is to turn off auto layout. Select the xib file from the project navigator, open the file inspector, and deselect the Use Auto Layout checkbox.
Read Constraints Express Relationships Between Views to learn how views are constrained in Xcode 4. In fact, you probably want the entire Cocoa Auto Layout Guide.
Briefly, when you add a view to your view hierarchy, it comes with some constraints. Select the view in the and you'll see some blue lines that look a bit like I-beams -- these represent the constraints. Click on one of them and you can edit its properties in the attributes inspector. But how you should set the attributes probably won't make much sense until you've read about how constraints work in the document linked above.
I'm following the instructions for creating a ScrollView in the book 'Cocoa Programming for Mac OS X, 3rd Edition'. I'm using Xcode 3.2.3.
I've already created a view, into which I've drawn shapes and lines.
The next task is to convert this to a NSScrollView, which according to the book should be a simple case of selecting the existing view and choosing Layout -> Embed Objects In -> Scroll View.
However whatever object I select, the items in the 'Embed Objects In' menu are all disabled.
How can I enable the Embed Objects In -> Scroll View item?
Got it. The important thing here is not to try selecting the view in the MainMenu.xib window. Select the view in the actual document window and make sure the resize handles are visible. A little fiddly, but once you get the right object selected, then the embed objects menu items become enabled.
I've been making iOS apps for awhile, but I'm trying my hand at MacOS development. I'm adding an NSTextField to my UI and I noticed in Xcode that one of the options in the graphical widgets is "NSTextField with NSNumberFormatter" which implies to me that I'll be able to restrict the input of the field to numbers and configure the formatter in some way.
When I add the NSTextField with NSNumberFormatter to my UI, I can see it has a formatter outlet which appears to be kind of linked to an NSNumberFormatter (although the name is a little grayed out). However, I can't figure out any way to interact with or configure that NSNumberFormatter.
Any help?
To access the NSNumberFormatter, you have to select it in the dock (that list of objects on the left side of the XCode 4 Interface Builder [IB] window).
If the dock isn't in outline view, e.g., it just shows about 4 icons, click the triangle-in-a-square-button at the bottom of the dock. The dock should now show a "Placeholders" section and an "Objects" section; the objects are your UI objects in a hierarchical outline view.
In the IB window, click your NSTextField; that'll highlight the corresponding Text Field Cell in the outline (you may have to twiddle down some disclosure triangles to see it). The Text Field Cell should have a disclosure triangle; twiddle it down to reveal the Number Formatter. Select it, and you should now be able to manipulate it in the Inspector panel.
(There are a lot of things non-obvious like that in XCode. When in doubt, examine your UI object in the Dock's outline view, or prowl the menus with that object selected. It's amazing--and often useful--what you can discover lurking there!
to configure the number formatter, you can ( after you've selected the formatter ) open the Attributes inspector, select the behavior you want and customize the formatter. At least that worked for me in XCode 4.
– moritz
I am trying to use the Core Data Entity in my app by dragging it onto a nib file within Interface Builder but it doesn't appear to be in my Library of controls.
Any idea how to get it in there?
Thanks
Graeme
I notice this is iOS tagged, so bad news: Core Data support in Interface Builder only exists for Macs, not iDevices (so far.) Make a MacOS X nib, not an ios nib, and you'll see "Managed Object Context" and "Core Data Entity" in the library. IB's Core Data support heavily uses Cocoa Bindings, which are also only available in MacOS proper (so far); without bindings it's not really meaningful to wire up model objects in the nib.
To see how to use core data without setting things up in IB, make a new iOS project with the "Navigation-Based Application" template, and check the "use core data for storage" checkbox. The meat is in the app delegate and RootViewController classes it creates; the nibs just contain VCs and UIViews, as normal.
The Core Data Entity doesn't exist in the Cocoa Library in Xcode 6.2. Instead, you can use an ArrayController.
1) Create a New project in Xcode: enter the project name and check the box that says Core Data.
2) In your project files, select the .xcdatamodeld file, and in interface builder setup an entity, which is like a Cocoa class with some #properties:
Click on Add Entity at the bottom of the window. In the image above, the entity is named Book. That line initially will say Entity instead of Book. Double click on Entity and type in Book.
Click the + in the attributes area to add the attributes and their types. To the far right, (with the rightmost icon selected at the top) you can check or uncheck other properties for the attribute, for instance uncheck optional.
As far as I can tell, setting up an entity is just like creating an Objective-C class with a bunch of #properties.
3) Select MainMenu.xib and drag a TableView(make it cell based) and a couple of square buttons onto the window:
For the buttons, in the Attributes Inspector next to Image, select NSAddTemplate and NSRemoveTemplate respectively. In the TableView, double click on the column headers and enter the column names.
Once you have your view set up, drag an ArrayController from the Library to the Dock. In the Identity Inspector, change the ArrayController's Label to BookController as shown in the image above. The label allows you to refer to that specific ArrayController, which is handy if you have multiple ArrayController’s in your xib file.
4) Next, in the Attributes Inspector specify the entity, or the type of the object, that the ArrayController will store and manage:
Also check Prepares Content. That will cause the data saved to disc to load in the TableView when the TableView launches.
5) With the ArrayController still selected, go to the Bindings Inspector, and under Parameters bind the ArrayController to AppDelegate and for the keypath enter managedObjectContext. The managedObjectContext is responsible for writing the data to disc:
6) Next, bind the columns of the TableView to the ArrayController. Make sure you are selecting the Book Title column:
In the Bindings Inspector under the Value binding, bind to the BookController(the label given to the ArrayController). The Controller key arrangedObjects is a sorted array of all the objects in the ArrayController. And by specifying the Model keypath as title, you are telling the column to display the title of every object in arrangedObjects.
Select the Author column in the NSTableView and setup the binding in a similar fashion.
7) Select the + square button, and Ctrl+drag from the button to the ArrayController. After releasing, choose add: from the popup menu. Then select the - square button, and Ctrl+drag from the button to the ArrayController. After releasing, chose remove: from the popup menu.
Finally, setup a binding for the - square button, which will disable the button when there are no items in the TableView to remove:
Run the application and use the + button to insert entries into the TableView. I notice that if I stop the application using Xcode's Stop button, the data entered into the TableView does not save to disc. Instead, I have to choose Quit under the application name in the menu bar in order to save the data to disc.
I want to use the same sort of UI style of Xcode has right above the editor pane, as show below:
I've browsed through all the Views in Interface Builder and can't figure out what type of view this is. At this point I'm merely referring to the bar itself; not to the controls nested inside the bar, though I will be adding dropdowns in the same way as this.
What type of view should I be looking for?
TextMate uses one along the bottom of the editor too, which provides similar controls:
see:
$(DEVELOPER_ROOT)/Applications/Utilities/Accessibility Tools/Accessibility Inspector.app
just open Accessibility Inspector.app and move the cursor over the views you're interested in for details (you may need to enable accessibility options in system preferences.app).
it's also helpful to press cmd+F7 to lock onto a view and then to inspect its children.
so... 3 primary options:
1) if you want drag & drop convenience, you can simulate it with a Gradient Button
2) or you can use the button with a custom image in the button to achieve something closer
3) or just create a new view subclass and render it using a CGGradient or NSGradient