0

I am making an iOS application with Swift 2. I have set 10 buttons tags' from 1-10. I am creating a loop for which var i loops through all numbers 1-10. A button I created is set to that tag. I am trying to set that button's image to nil. Here is my code:

var button : UIButton
    for var i = 1; i <= 10; i++ {
        print(i)
        button = view.viewWithTag(i) as! UIButton
        button.setImage(nil, forState: .Normal)
    }

What am I doing wrong? I have set 10 buttons tags'

Pranav Wadhwa
  • 7,666
  • 6
  • 39
  • 61
  • When are you running this code? Have all the buttons been added as subviews of `view`? – divergio Sep 01 '15 at 08:33
  • The buttons are in my Main.storyboard. They have the tags as listed. This is part of the viewDidLoad. – Pranav Wadhwa Sep 01 '15 at 11:07
  • Please try setting a break point before the for loop, and then typing `po self.view.subviews` ? Then you can confirm that all the views are added and have tags. – divergio Sep 02 '15 at 03:45
  • Sorry divergio, I did not understand what you said. What do you mean by 'po'. Also, I get a break point 1.1 error while setting a breakpoint there. – Pranav Wadhwa Sep 02 '15 at 21:22
  • "po" is the debugger command to print an object. https://www.objc.io/issues/19-debugging/lldb-debugging/ I'm trying to see the value of `self.view.subviews` before entering the for loop. – divergio Sep 10 '15 at 08:46

0 Answers0