1, using Nsuserdefaults to transmit the value, this method is limited to the case of transmitting a small amount of data:
For example, if you want to pass a float value, use it when you need to pass it.
[[Nsuserdefaults Standarduserdefaults] setfloat:float forkey::@ "float"]
When you receive the value, use the
[[Nsuserdefaults Standarduserdefaults] floatforkey:@ "float"]
2, Nsnotificationcenter to pass the value
-(void) touchesended: (Nsset *) touches withevent: (Uievent *) event
{
Uitouch * Touch = [touches anyobject];
Cgpoint point = [Touch locationinview:self];
CGRect roundrect = [self rectneedrefreshfromthispoint:point];
Mlastpoint = Cgpointmake (-1,-1);
NSLog (@ "%s:point (%f,%f)", __function__, Point.x, POINT.Y);
[Self addtocurrentlinewithpoint:point.x y:point.y];
[Self endLine];
[Self setneedsdisplayinrect:roundrect];
NSNumber *pointx = [NSNumber numberwithfloat:point.x];
NSNumber *pointy = [NSNumber numberwithfloat:point.y];
Nsdictionary *pointdict = [nsdictionary dictionarywithobjectsandkeys:pointx,@ "Pointx", pointY,@ "PointY", nil];
[[Nsnotificationcenter defaultcenter]postnotificationname:@ "Passtouchedendpointmsg"object:self userinfo:pointdict];
}
Functions in the Message Center:
[[Nsnotificationcenter Defaultcenter] Addobserver:self
Selector: @selector (gettouchedpoint:)
name:@ "Passtouchedendpointmsg"
Object:nil];
-(void) Gettouchedpoint:(nsnotification *) Noti
{
Nsdictionary *pointdict = [Noti userInfo];
Touchedendpointx = [[Pointdict objectforkey:@ "Pointx"] floatvalue];
Touchedendpointy = [[Pointdict objectforkey:@ "pointy"] floatvalue];
NSLog (@ "%f:%f", Touchedendpointx,touchedendpointy);
}
Using the message to pass parameters has the following points: Object refers to the sender, in the poseter side of the userinfo can be stored in the parameters to be passed, must be nsdictionary type. Get this dictionary type on the center side by: [Notification UserInfo];
Transfer values between IOS view