【问题标题】:UIButton array makes really bad performancesUIButton 数组的表现非常糟糕
【发布时间】:2014-12-04 22:51:27
【问题描述】:

我正在尝试实现一个棋盘游戏,其中我需要一个 40*26 按钮的棋盘大小。

我按如下方式实现这个板:

sizeX = 7.55;
sizeY = 7.35;
for (int i=0; i<nb_lignes; i++)
{
    for (int j=0; j<nb_colonnes; j++)
    {
        UIButton * test = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [test setFrame:CGRectMake((100-sizeX)+(j*(sizeX)), 50+(i*(sizeY)), (sizeX), (sizeY))];
        [test setBackgroundColor:[UIColor redColor]];
        [test setAlpha:0.5];
        [test setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
        [test setTitle:[NSString stringWithFormat:@"%i %i", j+1, i+1] forState:UIControlStateNormal];
        [test addTarget:self action:@selector(touchBouton:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:test];
        [[LevelButton objectAtIndex:i] addObject:test];
    }
}

我没有做任何动作说游戏真的很慢。例如,当我尝试使用辅助触摸时,它真的很慢。 您知道如何提高应用的性能吗?

【问题讨论】:

  • nb_lignes 和 nb_lignes 是否包含数组计数??

标签: ios objective-c arrays performance uibutton


【解决方案1】:

你可以试试-[NSArray enumerateObjectsUsingBlock:]而不是使用for循环

更多详情可以查看this Stack Overflow answer about using it

【讨论】:

  • 感谢 Josh 正确更新
猜你喜欢
  • 2017-01-25
  • 2021-03-11
  • 1970-01-01
  • 2020-08-12
  • 2012-05-06
  • 2018-06-27
  • 1970-01-01
  • 2010-09-16
  • 2016-06-29
相关资源
最近更新 更多