私はCGPointsを使用して配置されたオブジェクトの配列を持っています。私のアプリでは、配列内のオブジェクトは配列されていない他のオブジェクトにその位置を通知する必要があります。私はNSNotificationが最善の方法だと理解していますが、CGINをラップしてアンラップする通知の「送信者」と「受信者」の例は、userinfoとして見つけることができません。誰も助けることができますか?NSNotification userinfoの例?
5
A
答えて
15
を、CGPointsは
で包み、開封することができます+ (NSValue *)valueWithCGPoint:(CGPoint)point
- (CGPoint)CGPointValue
NSValuesは、userinfoパラメータとして渡されるNSDictionaryに格納できます。例えば
:
NSValue* value = [NSValue valueWithCGPoint:mypoint];
NSDictionary* dict = [NSDictionary dictionaryWithObject:value forKey:@"mypoint"];
そして、あなたの通知で
:とpointValue:NSValue* value = [dict objectForKey:@"mypoint"];
CGPoint newpoint = [value CGPointValue];
1
通知とともに渡されるuserinfoオブジェクトは、単にNSDictionaryです。おそらくuserInfoにCGPointを渡す最も簡単な方法は、-numberWithFloat:を使用してX座標とY座標をNSNumbersにまとめることです。たとえば、XposとYposをキーとして使用して、userinfoディクショナリでsetObject:forKey:を使用することができます。
おそらくsetFloatのような方法で、NSMutableDictionaryの素敵なカテゴリにそれを包むことができます:ココアタッチ(ただし、ココア)で... forKeyか何か
関連する問題
- 1. NSNotification EXC_BAD_ACCESS
- 2. NSNotificationのuserinfoは、ボタンを押したときに積み重ね続けます。
- 3. のuserinfo
- 4. NSNotification addObserver:someOtherClass
- 5. TabBarControllersのNSNotification
- 6. NSNotificationのトラブル
- 7. userinfo facebook
- 8. UIImageのUserInfo
- 9. OCUnit NSNotificationデリバリーをテストする
- 10. NSTableViewDelegateとtableViewSelectionDidChange:(NSNotification *)aNotification
- 11. Android対応のNSNotification?
- 12. マルチスレッドでのNSNotification XCODE
- 13. UNMutableNotificationContentとuserinfoのカスタムオブジェクト
- 14. NSNotificationとNSThread
- 15. NSNotificationはiphone
- 16. NSNotification Listener iOS
- 17. Keycloak、openId-connect userInfo
- 18. NSNotificationセレクタメソッドが呼び出されない
- 19. NSNotificationは完全に
- 20. NSNotificationクラスでは、スーパー
- 21. NSNotificationとNSEventの違い
- 22. NSNotificationオブザーバーとしてのクラス?
- 23. オブザーバー通知のNSNotification命令
- 24. IdentityServer4 UserInfoエンドポイントの実装?
- 25. クライアントからのIdentityServer4 docの例のUserInfoエンドポイントにアクセスできない
- 26. NSNoticationを使用してuserInfo(NSDictionary)を別のオブジェクトに渡す
- 27. URI userinfoコンポーネントを使用した認証http:// userinfo @ hostname:サーブレット内のポート/パス
- 28. スイフト3:NSNotificationと通知
- 29. observeValueForKeyPathでNSNotificationを送信
- 30. GoogleドライブAPI v3 - UserInfoエンドポイントURL
ココアでは、あなたがNSPointFromCGPointを使用することができ、その後、NSValueのvalueWithPointを使用しています。 –
NS_BUILD_32_LIKE_64で事前定義されたビルドが可能です。この場合、NSPointはCGPointのtypedefです(常に64ビットビルドです)。 –