tags:

views:

30

answers:

1

In my Tab Bar application, I want the user to have a list of items.

in the nav bar, i have a button, that (hopefully) lets the user add items to this list.

that button presents a modal view controller with a txt field, and a done button

the list on the main page is a table view, with an array, as data source.

i want the mvc to be able to add objects (the text fields text) to the array that is created in the main pages .h file.

So, question is, how can I do this succesfully?

thanks,

Sam

+1  A: 

You can have a method in your table view controller called addObject:(YourObjectType *)theObject which will accept whatever object type you're filling the array with. When you press the done button in your modal controller, create the object, then call the addObject method, then dismiss the modal view. In the table view controller, add the object to the array, then reload the table view.

The other alternative is to pass the array to your modal view, then add the created object to the array within the modal view controller. Set up an ivar of type NSMutableArray and when you create the modal view controller, set its ivar to be the main table view controller's datasource array.

nevan
um. Im a bit of a newbie at this, can you put that simpler? or in code ?
Sam Jarman
I started typing in some code, but realized that it would take quite a bit to explain all this. I learned this technique from Beginning iPhone Development, it's well explained in that book. Sorry I can't help you more.
nevan
Ok, i'll look into it a bit more on google. Thanks. Perhaps i could email you it? and you fit it in?
Sam Jarman