문제

I want to send CGpoint to my maincontroller class. So I am using Notification to send cgpoint but I dont know how to extract from cgpoint from notification at receiver. I only get 0.00 on my log output.

Here is my code.

AT sender:

 NSValue *pointAsObject =[NSValue valueWithCGPoint:CGPointMake(touchDetectingView.lastTouchPosition.x, touchDetectingView.lastTouchPosition.y)];
  [[NSNotificationCenter defaultCenter] postNotificationName: @"swap" object:pointAsObject];

AT receiver Header file:

- (void)incomingNotification:(NSNotification *)notification;

At receiver M file

[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(incomingNotification:) name:@"swap" object:nil];

- (void)incomingNotification:(NSNotification *)notification
{
     NSValue *pointAsObject = [[notification userInfo] valueForKey:@"swap"];
    NSLog (@"Successfully received the test notification %f",pointAsObject.CGPointValue.y);
}

But I only get 0.00 OUTPUT ..

도움이 되었습니까?

해결책

- (void)incomingNotification:(NSNotification *)notification
{
     NSValue *pointAsObject = [notification object];
    NSLog (@"Successfully received the test notification %f",pointAsObject.CGPointValue.y);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top