Which Cocoa UI element(s) should I use to display table like information - Mac OS X? - objective-c

I want to display information of a person, it would look like:
Name: Tom
Address: Long address, multi line,
next line, Long address
Comment: some text
Please notice that each property may be multi-line text. The UI widget should auto resize height to fit the content, if new information is loaded.
In a web app, I know it can be done by layout with table. But how can I do this in a Cocoa Mac OS X app?
----- edit -----
To make this question more precise, assume this use case:
I have a view(widget, control) that display text.
The text is dynamically set.
The view's width must be(or is set to be) fixed.
The view's height automatically adjusted depending on the text, text may be wrapped into several lines.
My question is, is there a cocoa view to do this? I don't want to calculate and set the height programatically .

You'd be looking for NSTableView if it's to be the same information for many (or more than 1) persons. Details can be found here: About Table Views in OS X Applications.
(some nice sample code on Apple's site as well, just follow the links in the class reference)
Or if you're just displaying information for 1 person you could use a bunch of NSTextField s (the read-only flavour is called Label in Interface Builder).

An NSTableView would probably suit best, but it depends on how you want your UI to look and feel.

Related

What class does Qt designer use to edit the properties of UI elements?

At the moment I'm writing a tool to extract parts of frames of mp4-video files. You draw rectangles on the video and the tool extracts .png-images at regular intervals. Now I want to give the user the ability to edit the properties of individual rectangles they have drawn on the video (exact position, frequency of frame extraction, time frame, etc.). I like the approach that QtDesigner takes for editing ui elements. You can see what I mean in this screenshot i found on the internet
The yellow and green table contains name value pairs for the different properties of the selected ui element. The table is devided into section depending on what class the property was inherented from. In the Screenshot the green part is inherented from MarbleWidget. The yellow part is inherented form a different class. I want each division to refer to a different rectangle and the color to match the colour the rectangle is drawn in on the screen.
I've tried using QTreeView, QTableView, QToolBox and QTableWidget but none of these - to my knowledge - offer putting QWidgets in the "value" part of the table. In the screenshot you can see tick boxes for example. In my case I would want to use a range slider. Does anyone know what class is used to Implement this table?
I think you'll find it difficult to use the designer classes in a normal application.
See qtpropertybrowser for a properties editor.
See setIndexWidget for a static widget. As it says, use QItemDelegate for dynamic widgets. Note that the specific item subclasses have their own methods like QTableWidget.setCellWidget.

Extended NSTableView

I would like to make a table-view with expanding ability.
When you press a row, the row should expand to show options like delete, copy and so on.
I have found an example for iOS, but I didn't get it running on Mac OS X, because NSTableView and UITableView are very different.
http://www.cocoacontrols.com/platforms/ios/controls/kofiles
Has anyone another template?
Or maybe even get this example running on Mac OS X?
I don't have code to hand you but you can use a view-based NSTableView. Your prototype view can resize itself to include controls if it's selected. All that's a bit complex to condense into a reasonably brief answer but if you use a view-based table view and treat the prototype view like any other that would grow and show extra controls, then wire this behavior to the selection state, it should work.
Note: you will have to write some code for the expansion portion, to handle resizing it, showing the controls, and notifying the table view that one of its rows changed height. Lots of documentation and examples exist out there for each individual component of your problem. Post more specific questions as you run into roadblocks.

iOS dynamically filling search results

I am building a small Search app on iPad. I want to show the search results. Do I use UIScrollView or UITableView?
The number of search results are unknown & as the user scrolls vertically I'll want to dynamically keep fetching the results & fill whatever container I will be using. Something like what Google Reader (on web) has.
For this purpose which is better suited? UIScrollView or UITableView? Also please guide me as to how dynamically populate the results?
This is an awesome question. I have a different approach for a solution to this problem. It is not the exact answer; But I would assume that the logic might be helpful -
Algorithm:
Decide on a certain number of records being pulled into the UITableView. (lets say 8 ).
You can use a UIScrollView with a small size (rather than setting it with smaller stepping size & frame).
Using the clipsToBounds property (set it to NO), you can actually track the amount of scroll, and check if it goes out of bounds
After you go beyond the bounds, initialize a new UIScrollView with a fresh-list of tables, and get another 8 data entries, and this can be continued.
Reduce the size, set the property and it would work.
But the problem with this is that ; if you try to touch outside the scrolling area => it will not scroll up/down.
Please refer to this tutorial, which can offer some intel on this idea.
And for setting the Scroll amount for Page control => Refer to this question on Stack Overflow.

How to change font size in a pickerview?

I'm fairly new to iPhone programming and am trying to implement a double-component PickerView. At this point the picker works fine in terms of taking user input, created with Interface Builder. However, I need to change the font size to accommodate the text length in each column. I very much would appreciate any link to a straightforward method to creating a multi-component picker with an adjustable font size. Seems like it is not possible if Interface Builder is used to create the picker. So far I have not found any code links that address this issue in detail.
Thanks in advance.
You need to implement the delegate method...
pickerView:viewForRow:forComponent:reusingView:
... and then alter the font of the UI element inside the provided view. I think the default is a UILabel. Alternatively, you can provide your own custom view.

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.