iOS模型视图控制器设计模式
如何在代码中实现MVC设计模式iOS模型视图控制器设计模式,ios,Ios,如何在代码中实现MVC设计模式 控制器->使用RestKit调用Rest服务 将JSON绑定到作为模型的对象-->上 控制器根据模型显示一组数据 现在在哪里实现视图? 我遗漏了什么吗?您的ViewController应该观察模型的更改并更新其视图层次结构,其根是self.view - (void)viewDidLoad { [super viewDidLoad]; // observe the model, via kvo, or subscribe to notificatio
我遗漏了什么吗?您的ViewController应该观察模型的更改并更新其视图层次结构,其根是
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
}
如果您使用的是
UIViewController
,那么它将有一个“视图”和一个“控制器”。这是一个很好的起点: