这是我关于 Stack Overflow 的第一个问题,所以我希望我足够清楚。
我正在为 iPhone 设计游戏,但无法显示某些对象。我有一个 NSMutableArray 对象(子类 UIImageView 的自定义对象类),我希望能够将它们全部显示在屏幕上。但是,数组可以改变大小,所以我不能直接链接界面生成器中的每个元素。有谁知道我如何开始解决这个问题?
谢谢!
编码:
//This code is in the viewController.m file
//The main array of objects is nodeList. Each node subclasses UIImageView.
//nodeList was also synthesized at the beginning of the file with @synthesize.
//initialize array
nodeList= [[NSMutableArray alloc] initWithCapacity:(vertLinks*horizLinks)];
//make center node
Node *n = [Node alloc];
//Initialize the node (just puts an x and y position in, and gives it a mass)
[n nodeInit:(startX):(startY):(nodeMass)];
[nodeList addObject:(n)];
//creates a 'web' of nodes, and adds each one to the array
for (int i = 1; i < vertLinks; i++)
{
for (int j = 0; j < horizLinks; j++)
{
//draw the line to each point
int nodeX = (startX + cos(((360 / horizLinks) * j) * (M_PI / 180)) * rad * i);
int nodeY = (startY + sin(((360 / horizLinks) * j) * (M_PI / 180)) * rad * i);
//add it to the screen
Node *nd = [Node alloc];
[nd nodeInit:(nodeX):(nodeY):(nodeMass)];
if (i == vertLinks - 1)
{
nd.solid = true;
}
[nodeList addObject:(nd)];
}
}