0

I'm trying to build a To-do list application. I have 2 tablesviews and one textfield. In the first tableview are the different projects, and when you click on one of them the associated todos appear in the second tableview. It's a pretty basic Master-detail I guess.

I set it all up with bindings.

Right now the way you add a task, is you click on an add button and it adds a row with a placeholder text that's editable. But what I want, is the user to enter the task in the textfield, press add, and then it adds the todo with the name already set.

So basically I have TodoItem Class with a name property, and my question would be, how do I get the content of the nstextfield and assign it to the name property ?

I tried creating an outlet from the Todoitem class to the textfield, but xcode won't let me connect it....

Tell me if you need to see any code, but since I used bindings, there's almost nothing to show. Thanks!

Max
  • 3
  • 1

1 Answers1

0

… how do I get the content of the nstextfield and assign it to the name property ?

Translate that directly into Objective-C:

NSString *contentOfTheNSTextField = [myTextField stringValue];
myNewTask.name = contentOfTheNSTextField;

You'd do that in the action method that you've set both the button and the field to call.


I tried creating an outlet from the Todoitem class to the textfield, but xcode won't let me connect it....

To do this, the Todoitem would need to reside in the nib.

But, even if you could do that, why should the model object know about the text field? Carrying values between model and view is a controller's job.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
  • Thanks you very much for the answer! As you probably figured out, I'm a newbie. About taking care of it in the model, does that mean I have to ovveride the add: method of the NSArraycontroller, that manages my task? – Max Jul 23 '13 at 19:33
  • @Max: I generally leave array controllers and other object controllers alone. I'd subclass the window controller instead. If you want to do it in the AC, it'd probably work, but you should override `newObject`, not `add:`. – Peter Hosey Jul 23 '13 at 21:46