user1688346
user1688346

Reputation: 1970

iOS Model View Controller Design Pattern

How do I exactly implement MVC design pattern to my code?

  1. Controller -> Call Rest Service with RestKit.
  2. Bind the JSON to a Object --> Which is A model
  3. Controller display bunch of data based on the model.

Now where do I implement View? Am I missing something?

Upvotes: 0

Views: 389

Answers (1)

danh
danh

Reputation: 62686

Your ViewController should observe changes to the model and update it's view hierarchy, whose root is self.view.

- (void)viewDidLoad {
    [super viewDidLoad];
    // observe the model, via kvo, or subscribe to notification, or make self == somebody's delegate, etc.
}

- (IBAction)doSomething:(id)sender {
    // change the model  [self.model change]
    // or start a web request with self as delegate
}

// called by kvo or delegate or notification or [self modelDidChange];

- (void)modelDidChange {
    // update self.view or children viewWithTag: or outlets setup to subviews
}

Upvotes: 2

Related Questions