Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Help with bindings...

Help with bindings...
Thread Tools
Fresh-Faced Recruit
Join Date: Jan 2001
Status: Offline
Reply With Quote
Jan 15, 2005, 05:44 PM
 
Hello all,
I'm working on an app to turn a comma delimited text file exported from an old PIM into a bunch of vCards and am having trouble getting bindings working properly. Currently, I have two table views set up. One is set up using a data source and the other is using bindings. I'm reading the string into the array using componentsSeparatedByString. In the data source view, it displays correctly (i.e. every comma delimited value on its' own row). In the bound table view, the string shows up on one row with all the elements separated by commas and all of that is enclosed in parentheses. Can someone tell me what I'm doing wrong? Here's the implementation:

- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType {
NSString *stringFromFileData = [[NSString alloc] initWithData: data encoding: 1];
[stringFromFileData retain];

[self setInfoArray: [stringFromFileData componentsSeparatedByString: @","]];

[stringFromFileData release];

return YES;
}

Thanks,
Kevin
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jan 15, 2005, 06:10 PM
 
Your mistake is in how you set up the binding, but I can't tell you more than that since I don't know how you did it. The code to read the file is correct, and obviously it's wording since one table view is presenting it correctly. The other table view is printing a description of the array.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Fresh-Faced Recruit
Join Date: Jan 2001
Status: Offline
Reply With Quote
Jan 16, 2005, 12:46 PM
 
OK. Let's do it the easy way...
.mac file sharing

As a side note, when I tried to delete the contact class, I get an error from PBXCP saying the file is no longer there, but when I deleted the files contact.h and .m I said to remove references. How do I fix this?

Thanks,
Kevin
     
Forum Regular
Join Date: Aug 2003
Status: Offline
Reply With Quote
Jan 16, 2005, 02:59 PM
 
Kevin:


Dled your project and looked at it a bit. Several things wrong, but first some questions:

1. Are both of the tableviews supposed to have the same content?
2. What is the NSArrayController in the nib for? It's not hooked to anything.

Things that are busted:

1. The only document you have is .rtfd, which is a package file (folder), but you only implement the - (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType method, which is to handle single files. You need to implement - (BOOL)loadFileWrapperRepresentation:(NSFileWrapper *)wrapper ofType:(NSString *)docType if you wish to read rtfd.
2. How the hell did you get objective-c class files INSIDE a nib? Delete that nib from your project, but delete references only. Then drag the nib back in.
3. You don't need to retain something you just inited.


Before I can help you fix your project completely, I must know the answers to the first two questions.
-- Devin Lane, Cocoa Programmer
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jan 16, 2005, 03:43 PM
 
He already said they're supposed to have the same content. One uses bindings and the other uses a traditional data source.

I took a look at it too, but I can't reproduce the problem. First I had no way to read in a document, so I made a dummy array and put it in infoArray. Then it was yelling at me about not being able to convert the array into a BOOL, and it turned out that for some reason the editable settings on both the NSArrayController and the NSTableColumn were bound to the array. After removing that, the list displayed fine.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Fresh-Faced Recruit
Join Date: Jan 2001
Status: Offline
Reply With Quote
Jan 16, 2005, 07:59 PM
 
Devin:

Answer to first question is yes, they're both supposed to show the same thing for now. I only did that to make sure I was reading the string correctly. And the second question is probably answered by my seemingly infinite lack of understanding of making bindings work properly. I want the first table to display the values of the array using bindings, but I just can't get it to work.

1: I guess I should just change the type to RTFD then. It should only be reading in simple text files. I just picked RTFD.

2: I don't know how I did that. I've noticed that a couple of times when I've generated files in IB they don't show up in xcode. They're created in the project directory, but I have to manually drag them in to the project. Maybe they were inserted into the nib that way.

3: I was having memory related crashes so I thought I would try it. I haven't removed them yet.

So what should I do to make the top table look like the bottom table?

Thanks,
Kevin
     
Forum Regular
Join Date: Aug 2003
Status: Offline
Reply With Quote
Jan 17, 2005, 12:38 PM
 
Kevin:

Here's how to set up the bindings.

1. Inspect the NSArrayController (green thing) in your nib file. Change the Object Class Name to NSString.
2. Remove the infoArray key from the NSArrayController
3. Bind the NSArrayController's content array to the File's Owner, using the "infoArray" key.
4. Bind the value of the only table column in the top table view to the NSArrayController, but without a model key path.
5. It works.

If these directions were unclear, or you just don't want to do them, the modified nib can be found here.

Also, you should be changing your document type plain text -- I see no place in your code where you are parsing RTF, nor even capable of loading RTFD.
-- Devin Lane, Cocoa Programmer
     
Fresh-Faced Recruit
Join Date: Jan 2001
Status: Offline
Reply With Quote
Jan 17, 2005, 10:10 PM
 
Thanks Devin. I just realized why I should have been binding to NSString. It makes sense; and I hate being a newbie. Thanks again.

Kevin
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:05 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2