在faceview里加入委托,让faceview可以获得数据,也就是笑脸的程度。同时controller把自己设为被委托者,实现faceviewdatasource协议里smileforfaceview的方法,并将自己作为返回值发送给faceview的datasource,然后faceview开始重绘笑脸。
float smile=[self.dataSource smileForFaceView:self];//这里接收controller传来的数据
@interface HappinessViewController ()<FaceViewDataSource>//协议的私有实现
[self.faceView addGestureRecognizer:[[UIPinchGestureRecognizer alloc] initWithTarget:self.faceView action:@selector(pinch:)]];//拉伸手势识别
[self.faceView addGestureRecognizer:[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleHappinessGesture:)]];//拖拽手势识别,调用下面的handlehappinessgesture方法,计算happiness的值,用来发送给faceview,也就是委托者。
self.faceView.dataSource=self;//这里就是设置委托
@class FaceView; //前向引用
首先,按住control,从想要发起segue的按钮处拖拽,拖到其他你想要实例化并放到屏幕上的控制器,所以xcode中,这些新控制器并不真的存在直到被segued,
而且segue总是实例化一个视图控制器,不会segue一个已经存在于堆上的,总是创建新的,离开的时候大部分都会消失,控制器生命周期短暂,所以内存消耗很低。
segue有两个重要属性,一个是identifier,赋予segue名字,在代码中通过名字来执行segue,
另一个是style,其中push is the kind of segue you use when the two controllers are inside a UINavigationController. 还有modal和custom。modal相当于确认框,轻易不要用。
the segue offers the source VC the opportunity tp prepare the new VC to come on screen. this method below is sent to the VC that contains the button that initiated the segue.
-(void)prepareForSegue:(UIStoryboardSegue *)segue
{
if([segue.identifier isEqualToString:@"DoAParticularThing"])
{ UIViewController *newController=segue.destinationViewController;
//send messages to newcontroller to prepare it to appear on screen
//the segue will do the work of putting the new controller on screen
}
}
You should pass data the new VC needs here and let it run;
接管视图的VIEW不能回头跟你说话,只能通过TARGETACTION或者委托。