Passing model objects from one view controller to another in a navigation stack

前端 未结 5 1322
刺人心
刺人心 2021-01-24 04:58

I have two UITableViewControllers. One displays a list of names and on tapping any cell will push the second TableViewController which enables the user to edit the name in a UIT

5条回答
  •  野性不改
    2021-01-24 05:38

    I see mainly three options:

    1. you could define your model as a singleton, which is easily accessible from every other object. In this case think about concurrent access to the model, it any;

    2. have the model private to the first controller, but instead of passing the string to the second controller, pass a pointer to the model, so you can read and write to it;

    3. pass the second controller a pointer to the first, so you can signal it (by calling some specific method); this is ok if you subclass the controller, otherwise you should use a delegate.

    A fourth option would be using notifications, but I think that 1 or 2 a the way to go.

提交回复
热议问题