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'm facing a new problem with adding my buttons.
Now I'm adding buttons to the bottom bar. They show up, with the image, but...
the action is never being called.

This is proberbly a simple fault so hopefully someone can help me out here

Code:
for(int a=0;........
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                                 NSUserDomainMask, YES);
            NSString *documentsDirectory = [paths objectAtIndex:0];
            NSString *path = [documentsDirectory stringByAppendingPathComponent:
                              [NSString stringWithFormat: @"%@/favorites/%@", theSub, [currentFavoriteImgs objectAtIndex: a]]];
            UIImage *favoImage = [UIImage imageWithContentsOfFile: path];
            
            UIButton *favoButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            [favoButton setTag: a];
            [favoButton setTitle: @"" forState:UIControlStateNormal];
            favoButton.frame = CGRectMake(x, y, size, size);
            [favoButton setBackgroundColor: [UIColor clearColor]];
            [favoButton setBackgroundImage: favoImage forState:UIControlStateNormal];
            [favoButton setBackgroundImage: favoImage forState:UIControlStateHighlighted];
            [favoButton addTarget:self action:@selector(chosenBtnAction:) forControlEvents: UIControlEventTouchUpInside];
            
            [bottombar addSubview:favoButton];

I'm really struggling for a few hours now :mad:
 
What does your chosenBtnAction: method look like?

Like this:
Code:
-(IBAction)chosenBtnAction:(id)sender {
    [self closeButtons: @""]; //Some function to close buttons animated
    NSLog(@"BLAH PRESSED BUTTON!");
    
    NSUInteger index = [@[@"page",@"gallery",@"lostfound", @"map", @"calendar", @"events"] indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
        return [obj isEqualToString:[currentModules objectAtIndex: [sender tag]]];
    }];
    NSString *theNextView = nil;
    
    switch(index) {

It looks like I can't press these buttons... Because the image is not getting highlighted or anything

(I'm using the same function in my sidebar, and that works fine)
 
Well, you're using the same image for both normal and highlighted states, so that probably doesn't help:

You are right about that one ;-)
That's why I have quoted it out in my project, see for any difference, but it doesn't make any..

I don't even get my
NSLog(@"BLAH PRESSED BUTTON!");
Even if I quote out the [self closeButtons: @""]

When I put a button manually with the a tag for an .. test. It does work properly, but the buttonbar must be dynamic :)

For now I will workaround it. As the 'favoButtons' will be a max of 5, I will put 5 buttons in place, and change the image programaticly...

Still I'm hoping that someone can help me out of this, because its not funny! :(
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.