0

Can anyone guide me as to how to create a table using Objective C for Mac OS X. The program should read values from an NSArray object and display the values in the table. I would appreciate it if anyone helped me out.

0

2 Answers 2

1

You need to implement a class that responds to NSTableDataSource and instantiate this, attaching it to your table as the datasource.

A quick search of NSTableDataSource (or indeed NSTableView [or for that matter Table]) in the Developer Docs should get you the details you need.

Edit:

You'll need to implement a couple of methods on your datasource as appointed to the tableview:

- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView {
  return [myArray count];
}

- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {
  return [[myArray objectAtIndex:rowIndex] objectForKey:[aTableColumn identifier]];
}

Together these two should just about do exactly what you need.

Sign up to request clarification or add additional context in comments.

2 Comments

Hey iam a newbie to obj-c ,iam just out of collg and i have joined a company 3 weeks before and i started obj-c just two weeks before so plz bear with me ..My task was to parse an xml file and display the attributes and its values onto a table... I have coded the backend i.e i parsed the xml file and stored each profile in an NSMutableDictionary obj and finally created an NSMutableArray and stored the dictionary objects into it..so this is working fine..but my issue is with the frontend...i dont kno how to create the table and display the contents of the array in it..so plz help me out.
@lohith: There you go. In addition you need to assign whatever object these are implemented on (your controller object, probably) to the tableview as its datasource (you do this in Interface Builder).
1

In answer to another question ( How to add a scrollable NSTableView programmatically ), I created the following sample application:

http://ericgorr.net/cocoadev/TableViewInCode.zip

which will demonstrate what you need to know.

Being new to all of this, I would highly recommend:

(1) Picking up a copy of "Cocoa Programming for Mac OS X (Third Edition)" by Aaron Hillegass

(2) Picking up a copy of "Cocoa Design Patterns" by Erik Buck and Donald Yacktman

I would consider these to be two must read books for anyone just starting out.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.