Question

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!

Was it helpful?

Solution

… 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top