mutualmobile / VIPER-TODO

Example project architected using VIPER
MIT License
70 stars 15 forks source link

Passing data from One screen to another #1

Open ghost opened 10 years ago

ghost commented 10 years ago

Hey Guys, could you please add an update to the current TODO demo showing how to pass data from one screen to another. For example, when the user selects a TODO, showing that selected ToDo on a ToDoDetailViewController. This will give us a much needed understanding of how we can accomplish such stuff by making correct use of VIPER architecture.

Thanks a lot

cnstoll commented 10 years ago

I agree this is worth doing.

As an example use-case, what do you think about the notion of "editing" a TODO after you've created it? Would that exhibit the behavior you're hoping to see?

Thanks,

sebastianwr commented 9 years ago

Sorry for bothering you on multiple channels, @cnstoll I just found this and think GitHub is the best place to discuss this issue.

For a simple master-detail view, I would enhance the View Model with the properties needed for both master and detail view.

List View (Table Cell tapped) -> List Presenter ---(ViewModel)---> List Wireframe ---(ViewModel)---> Detail Wireframe --> ... -> Detail View

For an editing matter you could hold a reference to the database ID, but that would be a violation of the layer independence? I really don't know. Do you have any working implementations yet?

daria-kopaliani commented 9 years ago

This would be very useful for me as well. Thanks in advance.

onmyway133 commented 9 years ago

How about passing the ToDoItem from List View (row tapped) -> List Presenter (event handler) -> List Wireframe -> Detail Wireframe

Think of the Wireframe as the gateway and also the input for its module

ghost commented 9 years ago

The editing use case would not be much different from adding, the primary difference being that you need to have a way of identifying the TodoItem you want to edit. You shouldn't pass the actual TodoItem from the List view but get a new copy of the data in your editing interface.

The only identifying information for a TodoItem you have in the List UI is the name and due date, so the List module interface could define a new method for updating:

- (void)updateEntryWithName:(NSString *)name dueDate:(NSDate *)dueDate;

The rest of the behavior would follow closely to what is done with adding, the exception being that the Update module would receive entity data to pre-populate its view. You could even consider abstracting the editing interface as its own view controller and then add it as a child view controller in both the Add and Update modules.

daria-kopaliani commented 9 years ago

Hi @adamschlag, what about the case when you do not have all the information about the todo item in the List view, you need for Editing view? (I.e. you only show name and date on List view, but, let's imagine there is more to todo item and you can edit in Editing view). Would you then pass the ID of the todo item to Editing wireframe, so that Editing provider could fetch all the data from the model (server or database)?

ghost commented 9 years ago

Yes, at least that is what I've done. That way you don't have to pass more data than you need to any of your presentation modules, but you have a way to tie data together when navigating to a module that requires more detail.