What is the Label property under the identity inspector in Xcode 4? - objective-c

The place holder text for the Label property is 'Xcode Specific Label', which when googled turns up nothing.
I assumed it used for identifying the UI element in your code by it's 'Xcode Specific Label' and not the actual text that the button displays in the UI. If so I am interesting in using it in my code since I have buttons with similar functions whose actions I want to send to the same method and differentiate between the two with the sender property by name. I understand that you can do this through the object id but I think that using a name would be clearer. How would I do this?

The Label field identifies the UI element in Xcode. If you name the UI element using the Label text field, you'll notice that element's name changes in the object list, which is to the left of the canvas.
The Label field doesn't do much with regard to code. It exists to make things more convenient in Xcode. In fact, the whole Identity section of the identity inspector exists to make things more convenient for you in Xcode. Suppose you have three text fields in your window. Giving each text field a different label makes it easier to identify each text field.

just the name you typed for the view in the Document Outline,It's a convenient way for you to identify the views in Xcode. as the image shows: I update the view's name to contentView, that means the view is the scrollView's ContentView.

Related

Which control can be used in order to display a dynamic form (with various types of data)?

I'm facing the following problems:
We have meta data for items, each item can be a different type of NSControl, currently NSTokenField and NSTextField, but we might need NSCombo or other types.
I need to build a form in which each entry will have a label and an editable control.
this form has to be built dynamically since the items are retrieved from the server.
I've implemented it with NSMatrix, and apart from it looking pretty shabby, I'm faced with some visual issues I don't know how to solve.
The visual issue is every time I move the mouse over the NSTextFieldCell the tokens get drawn on the top left corner of the NSMatrix form.
now, I'm considering moving to another type of control,
I've googled for few hours, and found the following controls:
NSForm,
NSMatirx (parent of NSForm),
NSCollectionView,
NSTableView
which one of these is the most appropriate for this task?
I hope I am clear since I wanted to add pictures, but it wouldn't let me due to lack of "reputation points".
Thanks for your help,
Eyal.
NSTokenField is a subclass of NSTextField so you could use an NSTableView to display them.
You could also draw a custom NSCell with all elements in it. When each "item" has a different number of elements then this becomes a bit more complicated though.

Creating a view for user to fill up a form

I'm creating a view which provides some fields for the user to fill in - address, phone number etc.
I've seen apps that have populated fields with grey text like 'Fill in your name here' on the Name field, and when the user taps on it the text is gone, a keyboard appears and the view is zoomed in to the textfield(or whatever it is). Also, after filling up that field tapping the 'Next' button on the keyboard brings the user to the next field. I'm trying to do the same but I have no idea where to get sources on this. Pardon my poor googling skills ;p
Tried UITextView and UITextField but there isn't anything related to this on the Interface Builder. Figured it lies with the codes?
It'd be great if I can get some explanation or some links on how this works (: Thanks!
EDIT: okay I played around with the Interface Builder a lil more and realized I could set placeholder as the grey text.
It is in fact a UITextField.
You can get the greyed out text by setting its placeholder property.
I am not sure what you mean by zooming but usually they do use a scroll view or adjust the frame so that it isn't blocked by the keyboard.
The Next button is made available using a UIToolbar instance as the text field's inputAccessoryView. However the implementation is one's own and is not framework provided. You can look at this example to get started.

Creating custom combination of widget in Cocoa

I have seen that in Cocoa I can create a custom view using drawing primitives which allows me to draw what I like but at a very low level.
Instead I'd like to create custom widgets using a combination of existing controls. For example:
I'd like to create a table with images and combobox in cells
I'd like to create a custom widget wich is a combination of several (for example a list, a button and combobox)
How can I approach this problem ?
Secondly a typical cocoa developer uses external controls? Is there a repository or a list of interesting external custom controls (commercial or free) ?
I'd like to create a table with images and combobox in cells
There already exists NSImageCell and NSComboBoxCell. Are you sure you need to do anything different?
If the problem is that you want an image and a combo box in the same cell, you will have to subclass NSCell. Currently table views can only contain cells, not views, which makes your life harder (as understanding how cell drawing works is more difficult). That will change in Lion, however, so if you can wait until then, this will become easier!
I'd like to create a custom widget wich is a combination of several (for example a list, a button and combobox)
How is your custom widget different to just placing those three things in the same view?
You could write your own NSView subclass. When it's created, it should create a list, a button and a combobox and add them as subviews to itself. Your NSView subclass should handle the logic of keeping them in sync or doing whatever it is you want them to do. Then, to use this combination control in Interface Builder, you place a Custom View and set its class (rightmost tab of the inspector) to your NSView subclass.
BTW, on a tangent, are you sure you mean combobox? Loads of people coming from Windows get this one wrong. A combobox is a combination of a menu and a text field: it allows the user to enter custom text that is not in the menu. If you just want a dropdown menu of choices (and the user can't enter a custom one), you use an NSPopupButton.
Secondly a typical cocoa developer uses external controls?
Yes, sometimes. Things like BWToolkit can be very useful. There's a lot more that are just floating around mailing lists as code snippets, rather than being cleaned up and put in a library. Search for what you need to do!

Interface Builder won't allow drag/drop of text control to window

Noob dumb question, no doubt -- but here it is:
Trying to tutorialize myself with the Apple "Currency Converter" tutorial for Cocoa ( http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjCTutorial/05View/05View.html)
Embarrassingly, I'm stuck very early on where the instructions ask me to drag-and-drop a text field onto the Currency Converter window. When attempting to do so, I release the mouse and the text field runs animatedly back to the library palette, refusing to "stick" on the client area of the Window.
Clearly the window is readonly or lacks some state or prerequisite to accept the text field, but what?
Are you sure you're dragging a view object and not a cell? Double check that you're dragging NSTextField and not NSTextCell.
Be sure you're not grabbing a text CELL.
When you select the text field from the Library, check that the description is NSTextField
Have you added a view to the window? Because if there is no view then you won't be able to add any controls.
Drag a "View" object over to your window.

Draw Lines on gtk.TextView

I'm trying to show the "selection" of a certain sub-string in a
gtk.TextView by drawing a border around the word. The only way to mark
text in a TextView that I've found so far is by placing TextTags with
modified properties. This does not seem to offer a way to draw a border,
though, DOES GTK SUPPORT THIS OR IS THIS A PROBLEM WITH ONLT PYGTK
I figured out how to draw on a text view !!!
To begin with lets assume the reference to your gtk.TextView is in a variable called viewer, Inside one of ur classes
Also the draw function has to be called with an event called expose-event else the drawings will be refreshed and will not stay on the screen
The next part is the gtk.TextView consists of 7 types of gtk.gdk.windows on which u can draw
gtk.TEXT_WINDOW_WIDGET
gtk.TEXT_WINDOW_TEXT
gtk.TEXT_WINDOW_LEFT - not displayed by default
gtk.TEXT_WINDOW_RIGHT - not displayed by default
gtk.TEXT_WINDOW_TOP - not displayed by default
gtk.TEXT_WINDOW_BOTTOM
gtk.TEXT_WINDOW_PRIVATE
For the drawing to appear on gtk.TextView We have to draw on gtk.TEXT_WINDOW_TEXT
An Example Code is as shown Below
if(viewer!=None):
viewer.connect("expose-event", expose_view)
self.drawable=viewer.get_window(gtk.TEXT_WINDOW_TEXT)
def expose_view(self,window,event):
if(self.drawable!=None):
self.drawable.draw_line(self.drawable.new_gc(),1,1,30,30)
# (1,1) and (30,30) are the coordinates and u can give the values accordingly
In a gtk.TextBuffer tags are used to set one or more pre-defined text attributes. Without subclassing, this is limited to the properties of a gtk.TextTag, and doesn't include anything akin to a border or outline property. There is no difference between PyGTK and plain GTK+ in this regard.
While somewhat hacky, the easiest way to do what you want to do is to connect to the expose-event of your gtk.TextView, get the coordinates of your string and draw on event.window, which is the gdk.Window of the event provided in the expose callback.
(Note that you don't have to get and store the gtk.TEXT_WINDOW_TEXT window, you just need to check what window the expose event is for in the callback, probably ignoring the expose if it's not for the text window.)
Instead, you could presumably subclass one or more of TextBuffer/TextView/TextTag to add a border tag, but whether it's reasonable to do so is another question.