Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test if item in toolBar is FlexibleSpace item?

I want to know which UIBarButtonItem enumerated in self.toolbarItems is a button and which is flexible space item.

like image 713
Lukasz 'Severiaan' Grela Avatar asked May 19 '14 09:05

Lukasz 'Severiaan' Grela


2 Answers

As A-Live confirmed my findings that one is not able to query the UIBarButtonItem to check if it is FlexibleSpace (or FixedSpace) I've used tag to mark those items as flexible and fixed space (2 different integers) and put those numbers in the constant then in code I use:

for(int i=0; i<self.toolbarItems.count; i++)
{
    if(item.tag != TOOLBAR_FIXED_SPACE_TAG && 
       item.tag != TOOLBAR_FLEXIBLE_SPACE_TAG)
    {
        //count real button:)
    }
}
like image 151
Lukasz 'Severiaan' Grela Avatar answered Nov 15 '22 05:11

Lukasz 'Severiaan' Grela


The answer above I wasn't able to get to actually work, so I used this. Hopefully this can help someone:

 for(int i=0; i<[buttonArray count]; i++){
      UIBarButtonItem *buttonItem = [[self items] objectAtIndex:i];
      if(buttonItem.title){
           NSLog(@"Double Boom %@", buttonItem);
      }
 }

** Flexible/Fixed space doesn't contain a title... This is the only real difference I could immediately see. So, I am literally just checking for a title.

like image 1
rckehoe Avatar answered Nov 15 '22 06:11

rckehoe