【问题标题】:IBOutletCollection objects indexed wrongIBOutletCollection 对象索引错误
【发布时间】:2013-08-27 04:45:44
【问题描述】:

我在故事板上有 10 个 uibutton,我已将它们与 iboutletcollections 链接。然后我使用循环从 uiimage 数组中设置按钮背景图像。当我运行我的项目时,按钮索引与图像索引不同


这是我的代码

-(void)setButtonImages
{ 
  for (int i=0; i<imageArray.count; i++)
  {
    UIButton *b =[self.myButtons objectAtIndex:i];
    [b setBackgroundImage:[imageArray objectAtIndex:i] forState:UIControlStateNormal];
  }
}

【问题讨论】:

  • 显示一些代码Соёмбо Бат-Эрдэнэ..
  • self.myButtons 有什么?和imageArray 有吗?
  • self.myButtons 是 iboutletcollection,它有 10 个来自故事板的 uibutton,imageArray 有 10 个 uiimage 对象
  • 我的意思是值...尝试在这些行添加一个断点或者在for循环之前放置2个NSLogs
  • 我的问题是按钮索引与图像索引不同,它必须看起来像这样 button[0] = image[0], button[1] = image[1], ...... . button[n] = image[n],但是当我运行我的代码时,它看起来像这样:button[5] = image[1], button[1] = image[2], button[9] = image[3 ] 等

标签: ios sdk indexing iboutletcollection


【解决方案1】:

手动创建按钮,然后一一标记它们,您可以使用带有标记的按钮

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-30
    • 1970-01-01
    • 1970-01-01
    • 2012-01-09
    • 1970-01-01
    • 1970-01-01
    • 2021-08-12
    • 2018-02-27
    相关资源
    最近更新 更多