iphone - 在 NSMutableArray 中存储和检索 CGPoints

标签 iphone objective-c nsmutablearray nslog

我已经查看了这里和其他地方的无数问题,但终究无法弄清楚我做错了什么。

我正在尝试将 CGPoints 数组作为 NSValues 存储在 NSMutableArray 命名点中,就像在 iPhone 上一样:

NSValue *point = [NSValue valueWithCGPoint:firstTouch];
NSLog(@"NSValue *point = %@", point);
[points addObject:point];

NSLOG OUTPUT
NSValue *point = NSPoint: {120, 221}

从 CGPoint 到 NSValue 的转换一切顺利。但是,当我尝试检索该点时,我一无所获。

NSValue *getPoint = [points objectAtIndex:0];
CGPoint thePoint = [getPoint CGPointValue];
NSLog(@"Point = %@", NSStringFromCGPoint(thePoint));

NSLOG OUTPUT
Point = {0, 0}

点数应该相同,但我得到的结果为空。

出于测试目的,这是在 touchesBegan 方法中发生的。

有人知道我哪里出错了吗?提前致谢。

最佳答案

我从未将我的数组分配到内存中并对其进行初始化。我的点没有存储到数组中,因为不存在数组。

关于iphone - 在 NSMutableArray 中存储和检索 CGPoints,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2486270/

相关文章:

swift - 如何在 Swift 中不更改父 NSMutableArray

iPhone 到 iPhone 通信

ios - 指定初始化程序缺少对父类(super class)的指定初始化程序的 super 调用

objective-c - 阻止导航 Controller 导航并要求用户确认

ios - 合成的 NSMutableArray 返回 null

iphone - 创建 NSMutableArray 的副本并仅在一个数组中编辑元素

ios Facebook 登录显示 "Invalid Scope: basic_info"。使用 public_profile, user_friends 代替

ios - 重复使用 iOS 密码/拨号器键盘

ios - 应用商店的销售和趋势问题

objective-c - Cocoa ConnectionKit 框架依赖项