这个示例代码让我定义了一些东西,但我还不想定义?
我有一些开源代码,其中包括:
.h:
#define TILE_ROWS 6
#define TILE_COLUMNS 2
#define TILE_COUNT (TILE_ROWS * TILE_COLUMNS)
@class Tile;
@interface TilesViewController : UIViewController {
@private
CGRect tileFrame[TILE_COUNT];
Tile *tileForFrame[TILE_COUNT];
}
然后在整个 .m 中,如下所示:
for (int row = 0; row < TILE_ROWS; ++row) {
for (int col = 0; col < TILE_COLUMNS; ++col) {
and
tileFrame[index] = frame;
and
tileForFrame[index] = tile;
但我想要的是能够将 TILE_ROWS 设置为结果,例如:
float rowsNeeded = ceil(rowsNeededA/TILE_COLUMNS);
因此,它需要稍后再说,但我认为 CGRect 和 Tile 只能在那里定义。我需要帮助,我不知道该怎么办。
I have some open source code, which includes this:
.h:
#define TILE_ROWS 6
#define TILE_COLUMNS 2
#define TILE_COUNT (TILE_ROWS * TILE_COLUMNS)
@class Tile;
@interface TilesViewController : UIViewController {
@private
CGRect tileFrame[TILE_COUNT];
Tile *tileForFrame[TILE_COUNT];
}
And then throughout the .m, like so:
for (int row = 0; row < TILE_ROWS; ++row) {
for (int col = 0; col < TILE_COLUMNS; ++col) {
and
tileFrame[index] = frame;
and
tileForFrame[index] = tile;
But what i want is to be able to set TILE_ROWS to the outcome of, for example:
float rowsNeeded = ceil(rowsNeededA/TILE_COLUMNS);
So therefore it would need to be later on, but I think the CGRect and Tile can only be defined there. I need help, I'm not sure what to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须将定义转换为实例变量并动态分配数组:
for 循环变为:
You have to turn the defines into instance variable and to allocate the arrays dynamically:
The for loop then becomes: