0

I am very new to coding but I am striving to maintain a MVC design pattern at all costs!

I have an app whereby a tableview is selected which pushes to a new tableview. The plist and dictionaries are dealt with in the model class and it returns an array which populates the tableview. When one is selected, do I send that information to the controller than make some sort of query to get the next array, because I believe I can't go from view to model? I've heard of NSNotification, should I set that up somehow so that the model 'knows' what is selected?

Hindol
  • 2,924
  • 2
  • 28
  • 41
Rob W
  • 591
  • 1
  • 7
  • 22
  • 2
    This question appears to be off-topic because it is about coding style. This might be better on the Programmer Stack Exchange. – user1118321 Dec 24 '13 at 17:16

2 Answers2

1

From an MVC perspective, all the application logic should reside within the controller itself. Now decide for yourself.

What you want to do is not very clear to me though.

Hindol
  • 2,924
  • 2
  • 28
  • 41
  • Apologies for a lack of clarity. I have a table of 12 objects which is populated from a plist. When one is selected, it 'drills down' to another table which is populated by the second 'level' of the plist. In the didSelectRowAtIndexPath method, I can pass the 'selected' cell's information somewhere. Does that go to the controller which would then request the next array from the model again? Probably as clear as mud now I've tried to clarify!! – Rob W Apr 21 '12 at 20:27
  • That's the way to go. You would pass over selected model object (NSDictionary for example) which would be used as source for setting up your "child" controller and view. You can also pass strings from current cell data and get the actual object from that, but that's probably more work and more duplicated code. – Tom Apr 23 '12 at 17:20
1

In your case, it's perfectly fine to pass along the model data directly to the next tableview. In this case, the controller that manages the first tableview is going to pass the model data to the next controller (the one being pushed one if you're using a navigation controller). That's totally fine from an MVC perspective, and a really common way to do this sort of thing.

atticus
  • 960
  • 7
  • 10
  • Thank you very much for your response! The way that I did this previously was to have a property (i.e. a string with the selected cell's title) and set the property in the didSelectAtIndexPath method. Is that still a valid way to do things then? Or do you mean something slightly different? – Rob W Apr 21 '12 at 20:50
  • 1
    That's sounds exactly right. You usually create a view controller in didSelectRowAtIndexPath:, configure the view controller via properties or methods, and then present it somehow. – atticus Apr 21 '12 at 20:58
  • Excellent, that's very helpful kind sir! – Rob W Apr 21 '12 at 21:06