Display NSArray on window IB - objective-c

I have an application that reads/parses data into a file and store it into a NSMutableArray.
I need to display the contents (data) of this array into a window (tableview or else don't care) the only problem is that the data is not static so i can't fix n labels if you understand me.
If someone can help me
Thanks to all

This is for solve such problems that Apple design the UITableViewDelegate protocol
Follow the documentation and you should solve your problem.

This is a job for Cocoa Bindings.

Related

Ongoing NSTableView problems

I am writing my first Cocoa/OSX app. I have been having problems with an NSTableView derived class. The problems is that there is no table in the containing NSView - the table is not visible.
I previously pasted my code at NSTableView is not being displayed
If you know NSTableView well and it could assist, it would greatly help. I have spent a couple of days on this, with no luck.
Additional details:
NSLog shows that NSTableView subclass init() is called once. This is probably good. The method numberOfRowsInTableView() is called multiple times. I don't know whether this good or bad. The method tableView:objectValueForTableColumn:row: is never invoked. The method drawRect() of NSView is called after initialization of TableView. Yet, commenting out [super drawRect:dirtyRect]; line changes nothing.
Please note that I use the same NSTableView subclass as [also] a NSTableViewDataSource. I understand that this is not the common "pattern," yet I don't see why this cannot work. If there is a logical explanation, please advise my approach is not workable.
I do not use and do not want to use InterfaceBuilder.
Thank you for taking time to read my question.
I managed to come up with the solution. See the referred page for more information, if interested. Thanks.
BTW, the best NSTableView tutorial which I have seen - one that allowed me do what I needed is at: http://www.knowstack.com/nstableview_fromcode/

Customized UITableView

I just want to confirm that which is the better way for handling the highly customized table view, is it by using the nib file or writing the code for each element ourself.
This question has been asked not only in regard to UITableViews. You can see some tests here:
http://cocoawithlove.com/2010/03/load-from-nib-or-construct-views-in.html
If the cells are very complex, it is easier to create a nib file for the cell, like here
http://adeem.me/blog/2009/05/30/iphone-sdk-tutorial-part-6-creating-custom-uitableviewcell-using-interface-builder-uitableview/
Memory wise, I can't tell you for sure.
But considering you are talking about a highly customized table view, using nibs is better because you can actually see the modifications. This makes it easier for you. Otherwise it would be a real pain to create a highly customized cell only by code, not to mention that it would make it nearly impossible to be edited by someone else than a programmer.
The best way will be to create a separate nib only for your cell layout as described here: UITableViewController with custom UITableViewCell

The correct way to user custom UITableViewCells

I have seen a lot of different ways of implementing custom cells in a table view.
Like different file owners, get it from bundle and call the the latest obj of the array and a lot more.
But all did not feel right.
What is the best and correct way to create and use custom table view cells (with interface builder).
I think Storyboards are the new proper way. I use this method:
http://iphonedevelopment.blogspot.com/2009/09/table-view-cells-in-interface-builder.html
And it works quite well. I think it's somewhat proper in that you are asking the OS to do most of the work, although it's a little sneaky that the cell is assigned to a property as part of the NIB loading as a side effect.
Had the same problem. For me it is now solved with storyboards in ios5.

avoid dequeueReusableCellWithIdentifier to prevent UITableViewCell freezing

I am creating a custom UITableViewCell in which I am populating the cells with a JSon response of a web service. The problem is that the cell contains UIImage also which is creating problems when we scroll the cells (you can say freezing because of loading). I want to know the best practice of avoiding this behavior and also I want to know that is there any possibility that we don't use dequeueReusableCellWithIdentifier so we can prevent dequeueing of our cells.
Regards.
I found a good solution to accomplish this by using HJCache Library. Have a look at this and up-vote if you like :). Here is the link > HJCache Library
Happy Coding!

Best way to capture key events in NSTextView?

I'm slowly learning Objective-C and Cocoa, and the only way I see so far to capture key events in Text Views is to use delegation, but I'm having trouble finding useful documentation and examples on how to implement such a solution. Can anyone point me in the right direction or supply some first-hand help?
Generally, the way you implement it is simply to add the required function to your view's controller, and set its delegate. For example, if you want code to run when the view loads, you just delegate your view to the controller, and implement the awakeFromNib function.
So, to detect a key press in a text view, make sure your controller is the text view's delegate, and then implement this:
- (void)keyUp:(NSEvent *)theEvent
Note that this is an inherited NSResponder method, not a NSTextView method.
Just a tip for syntax highlighting:
Don't highlight the whole text view at once - it's very slow. Also don't highlight the last edited text using -editedRange - it's very slow too if the user pastes a large body of text into the text view.
Instead you need to highlight the visible text which is done like this:
NSRect visibleRect = [[[textView enclosingScrollView] contentView] documentVisibleRect];
NSRange visibleRange = [[textView layoutManager] glyphRangeForBoundingRect:visibleRect inTextContainer:[textView textContainer]];
Then you feed visibleRange to your highlighting code.
It's important to tell us what you're really trying to accomplish — the higher-level goal that you think capturing key events in an NSTextView will address.
For example, when someone asks me how to capture key events in an NSTextField what they really want to know is how to validate input in the field. That's done by setting the field's formatter to an instance of NSFormatter (whether one of the formatters included in Cocoa or a custom one), not by processing keystrokes directly.
So given that example, what are you really trying to accomplish?
I've done some hard digging, and I did find an answer to my own question. I'll get at it below, but thanks to the two fellas who replied. I think that Stack Overflow is a fantastic site already--I hope more Mac developers find their way in once the beta is over--this could be a great resource for other developers looking to transition to the platform.
So, I did, as suggested by Danny, find my answer in delegation. What I didn't understand from Danny's post was that there are a set of delegate-enabled methods in the delegating object, and that the delegate must implement said events. And so for a TextView, I was able to find the method textDidChange, which accomplished what I wanted in an even better way than simply capturing key presses would have done. So if I implement this in my controller:
- (void)textDidChange:(NSNotification *)aNotification;
I can respond to the text being edited. There are, of course, other methods available, and I'm excited to play with them, because I know I'll learn a whole lot as I do. Thanks again, guys.