开发者

Editing an array in a class, from a modal view controller

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 开发者_JAVA百科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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜