0

I've tried many of the answers that I've found here. I must be doing something dumb and could use help.

  1. in .h: @property (strong) IBOutlet NSTextField *title;

  2. in .m:

    title = [[NSTextField alloc] init];
    [title setStringValue:@"test"];
    NSLog(@"title is %@", [title stringValue]);
    
  3. In IB, the title field is set up like this:

enter image description here

and it's class is NSTextField.

I can get the data to show in the tableview, but I cannot link it to the textfield. Thanks for any help...

I do log the title field and that shows content:

  title is test
Maarten
  • 1,873
  • 1
  • 13
  • 16
ICL1901
  • 7,632
  • 14
  • 90
  • 138
  • This is really your code? Typo? NSMutableArray *currentItem = [itemArray objectAtIndex:row]; is only valid, if in the item array contains (mutable) arrays. If this is the case, [currentItem valueForKey:@"title"] will return an array of titles. (With one entry, but still an array.) – Amin Negm-Awad May 23 '13 at 19:15
  • shameful eh? I should have said that itemArray is populated from a parse.com query. I should also say that I am struggling with newly low vision, so I must dictate a lot of what i write. It's ok, but a bit tedious. – ICL1901 May 23 '13 at 19:39
  • oh, and i changed NSMutable to NSArray. Still the same results. – ICL1901 May 23 '13 at 19:41
  • 3
    I'm no OS X developer, but do you need to initialize an NSTextField that is being loaded from Nib? Also, shouldn't you set the instance variable `title` like this: `self.title = [[NSTextField alloc] init];`? Again: not an OS X developer, but that just caught my attention. – Maarten May 24 '13 at 07:55
  • Thanks Maarten. I do a test to see if the field is live (if title)log, and without the init, it shows empty. Thanks also for noting the self.... However, still no joy. I'm doing something dumb. – ICL1901 May 24 '13 at 08:48
  • @DavidDelMonte Can you update your code so we can see what it looks like now? If you are testing you code with `if (title) NSLog(@"Title exists.";` you're still only going to find out about your local var and not your instance variable. Try `if (self.title) NSLog(@"Title ivar exists with string value: %@.", [self.title stringValue]);`. – Maarten May 24 '13 at 11:29
  • Maarten, I changed my code (copied and pasted yours). I got a positive response. It can see the ivar. – ICL1901 May 24 '13 at 11:50
  • Okay, so what problem are you still facing? Have you changed all your code to refer to `self.title` instead of `title` like you were doing before? – Maarten May 24 '13 at 14:29
  • yes, i did. I will look again at all the code.. – ICL1901 May 24 '13 at 16:47
  • I have found that I can write to an NSLabel. Maybe that's a clue to someone.. – ICL1901 May 24 '13 at 17:45

1 Answers1

0

After looking some more on SO, I came up with this, that works as I need it:

NSInteger row =  [[notification object] selectedRow];
    currentItem = [itemArray objectAtIndex:row];

    [self.itemTitle setStringValue:
     [NSString stringWithFormat: @"%@", [currentItem valueForKey:@"title"]]];

Thanks

ICL1901
  • 7,632
  • 14
  • 90
  • 138