Mvc, as its name implies, model, view, and controllercontroller include model, view ------------- controller. h -------------- # import <Foundation/Foundation. h> # import "cocos2d. h "# import" mvcModel. h "# import" mvcView. h "@ interface mvcController: NSObject <CCTouchOneByOneDelegate> {mvcModel * mymodel; mvcView * myview;} @ property (nonatomic, retain) mvcModel * mymodel; @ property (nonatomic, retain) mvcView * myview; @ end ----------- controller. m -------------- # import "mvcController. h "@ implementation mvcController @ synthesize mymodel, myview;-(id) init {if (self = [super init]) {// a data model corresponds to a view, if multiple models correspond to multiple views, add an array in the controller to save their management self. mymodel = [[[mvcModel alloc] init] autorelease]; self. myview = [[[mvcView alloc] init] autorelease]; // implement the notify interface so that the controller can obtain the touch event [[[CCDirector shareddire] touchDispatcher] addTargetedDelegate: self priority: 0 swallowsTouches: YES];} return self;} // touch event Method-(BOOL) ccTouchBegan :( UITouch *) touch withEvent :( UIEvent *) event {static int x = 1; // Modify the title attribute in the model. view automatically modifies self. mymodel. title = [NSString stringWithFormat: @ "under % d", x]; self. mymodel. mypos = CGPointMake (100 + x, 100); // call the method to make the model change display [self. mymodel didChange: self. myview]; x ++; return YES;}-(void) dealloc {[[CCDirector shareddirecher] touchDispatcher] removeDelegate: self]; [mymodel release]; [myview release]; [super dealloc] ;}@ end ------------- model. h -------------- # import <Foundation/Foundation. h> // interface part @ class mvcModel; @ protocol ModelDelegate <NSObject> @ required-(void) modelDidChange :( mvcModel *) model; @ end @ interface mvcModel: NSObject {NSMutableSet * delegates; NSString * title; CGPoint mypos;} @ property (nonatomic, retain) NSString * title; @ property (nonatomic) CGPoint mypos;-(void) didChange :( id <ModelDelegate>) delegate; @ end ----------- model. m -------------- # import "mvcModel. h "@ implementation mvcModel @ synthesize title, mypos;-(id) init {if (self = [super init]) {delegates = [NSMutableSet new];} return self ;} // call the method in the interface, that is, call the method in the view that implements the interface-(void) didChange :( id <ModelDelegate>) delegate {[delegate modelDidChange: self];} -(void) dealloc {[title release]; [super dealloc] ;}@ end ------------ view. h --------------- # import "cocos2d. h "# import" mvcModel. h "// implement model interface @ interface mvcView: CCLabelTTF <ModelDelegate> @ end ------------ view. m -------------- # import "mvcView. h "# import" mvcController. h "@ implementation mvcView-(id) init {if (self = [super initWithString: @" mvc mode "fontName: @" Marker Felt "fontSize: 32]) {self. anchorPoint = ccp (0.5, 0.5); self. position = ccp (320/2, 480/2);} return self;} // model change call interface method change view display-(void) modelDidChange :( mvcModel *) model {self. string = model. title; self. position = model. mypos;} @ end summary: The controller completes the interaction with the user. The controller modifies its own model. After the model is changed, the view in the controller is changed through the Protocol and displayed to the user.