Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DennisBlah

macrumors 6502
Original poster
Dec 5, 2013
485
2
The Netherlands
Hi all,

I really need some quick help with this.
I'm searching on a button based on the tag.
As the buttons in the UIView buttons are images, I want to change them after they are pressed.

Code:
-(IBAction)buttonPressed:(id)sender {
...
...
   UIButton *button = (UIButton *)[self.buttons viewWithTag: [sender tag]];
   button.hidden = YES;
}

However.. the UIButton keep returning the UIView buttons. And my UIView buttons get hidden when I press the first button (tag 0)
Whilst I'm searching the UIButton in UIView buttons based on the tag.
Anyone has any explanation and solution for this ?

For all buttons it's working except for my 'home' button. Then the whole view gets hidden :s
Even when I set tag of the buttons UIView to something like 9999 and with a isMemberOfClass checksum I never get to the first button (tag 0)

p.s. the button.hidden is for testing
 
Last edited:
The default value of tag is 0. Therefore, all unassigned tags are 0. You most certainly have overlap. Don't use 0 as a "special case".
 
The default value of tag is 0. Therefore, all unassigned tags are 0. You most certainly have overlap. Don't use 0 as a "special case".

The uiview tag is 9999
But, oh wait I think that the uiimageview I use for background is 0 as well

I use 0 so I can throw the tag into objectatindex of my buttons array
 
Try this

Code:
-(IBAction)buttonPressed:(id)sender {

   UIButton *button = (UIButton *) sender;
   button.hidden = YES;
   NSLog(@"tag: %i", button.tag);
}
 
Try this

Code:
-(IBAction)buttonPressed:(id)sender {

   UIButton *button = (UIButton *) sender;
   button.hidden = YES;
   NSLog(@"tag: %i", button.tag);
}

This does work. However it will remove all the buttons with this tag.
(I got the same tags in another 'sidebar' which got the same functions).

I only want to hide the button with this [sender tag] that is inside the UIView buttons. That's why I was playing around with the viewWithTag
 
This does work. However it will remove all the buttons with this tag.
(I got the same tags in another 'sidebar' which got the same functions).

I only want to hide the button with this [sender tag] that is inside the UIView buttons. That's why I was playing around with the viewWithTag

Have you tried it?
the 'sender' above is the button that was pressed. That is the only button that will be removed. As you can see the tag of the pressed button will also be logged. The code I posted won't remove anything else.

If you are still playing with tags, remember the default tag is 0.
 
Have you tried it?
the 'sender' above is the button that was pressed. That is the only button that will be removed. As you can see the tag of the pressed button will also be logged. The code I posted won't remove anything else.

If you are still playing with tags, remember the default tag is 0.

I did try and it does work, but I really need to work with the tag. However it's removing all buttons with the tag
When I press like... gallery in the sidebar, the favorite icon of gallery must change, this one has same tag as the button the sidebar

This buttonbar is like.. Favorites of all the buttons.
What Im trying to say is, the same buttons (but only text) and same tag is in another view on the viewcontroller. Like a sidebar which slides in and out.
Favorites are also shown in a bottombar that is dynamic in size and the buttons are shown as icon which I want to change color when it's currently viewing that module or page
And only the favorites must change thats why I am trying with viewWithTag, also when I press the button in the 'sidebar' the favorites must change.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.