【问题标题】:how to create, fill and search on iphone xcode?如何在 iphone xcode 上创建、填充和搜索?
【发布时间】:2012-09-21 08:49:06
【问题描述】:

enter code herehi hackers :) 我在 xcode iphone sdk 中编程,这是我的问题:

假设我有图像(精灵)及其位置(x 和 y),我想找出哪个图像在例如 x=150 和 y = 104..

我会在 mySQL 中做

1) 包含:图像名称、x、y 的表 插入(sprite1.png,150,104) 插入 (sprite2.png, 104,390) ..etc

然后搜索

如果 x=150 和 y = 104 -> 我得到 sprite1.png .. 等等..

但是如何在 iphone 上做到这一点?当然我不会使用 mySQL,我需要 NSMutableArray 或 NSArray,对吗?但是

1) 使用哪个数组? (NSM 可变?) 2)如何在其中创建名称,x,y? 3)如何填写? 4) 如何按 x,y 搜索并获取名称?

你能帮我解决这个问题吗?仅用于 2 个示例精灵.. 谢谢! :)

编辑:第四个将是指针?用于访问图像..所以我想要名称,x,y,指针

edit2:我知道了,对吗?

name = [[NSMutableArray alloc] init];
x = [[NSMutableArray alloc] init];
y = [[NSMutableArray alloc] init];
images = [[NSMutableDictionary alloc] init];

【问题讨论】:

    标签: iphone xcode sdk nsmutablearray


    【解决方案1】:

    你是对的,你将使用一个数组。 为它定义一个数据结构作为一个目标 c 类。 这将是您的带有图像、x、y 信息的模态类。 然后创建一个此类的对象数组。

    然后在“for in”循环中查找数组中具有所需值的每个对象。

    例如:

    for(MyModalClass *modalClass in objectArray){
      if(modalClass.x == reqXVal && modalClass.y == reqYVal && modalClass.image == reqImageVal)
    //Do what you want!
    }
    

    【讨论】:

    • 谢谢@Apple_iOS0304,但坦率地说-我不确定如何定义数据结构。struct images { int xaxiss; int yaxiss; string name; }; names = [[NSMutableArray alloc] init]; //start of loop when creating images adding this info into struct? struct images imagesAll; imagesAll.xaxiss = 130; imagesAll.yaxiss = 120; imagesAll.name = Image1.png; names addObject:[images]]; //add to NSMutableArray?? //添加图像时循环结束这是存储数据的正确方法吗?我真的是这个初学者......
    • 我在这里所说的数据结构的意思是创建一个客观的 C 类。右键单击 Xcode IDE 左侧面板中 xcode 项目的文件层次结构并添加新文件。从那里添加一个继承自 NSObject 的新目标 c 类。现在使用这个类的对象有 3 个属性:urX、urY 和 urImage。因此,您将能够将数据存储在此类对象中并制作此类对象的数组。我希望我澄清了自己,如果没有,请告诉我。
    猜你喜欢
    • 1970-01-01
    • 2016-07-14
    • 1970-01-01
    • 2012-06-17
    • 2017-07-16
    • 2020-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多