views:

537

answers:

1

Hey There,

I'm having a little trouble using the tag property to access a UIButton

UIButton   *randomButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect ]];    
    randomButton.frame = CGRectMake(205, 145, 90, 22); // size and position of button
    [randomButton setTitle:@"Random" forState:UIControlStateNormal];
    randomButton.backgroundColor = [UIColor clearColor];
    randomButton.adjustsImageWhenHighlighted = YES; 
    [randomButton addTarget:self action:@selector(getrandom:) 
           forControlEvents:UIControlEventTouchUpInside];
    randomButton.reversesTitleShadowWhenHighlighted=YES;
    randomButton.toggleButton

    [self.view addSubview:randomButton];

    randomButton.tag=333;

Then later on in code I try to get at the button in the following manner which gives me an error saying

Incompatible Objective-C types initializing 'struct UIView *', expected 'struct UIButton *'

UIButton *random = [self.view viewWithTag:333];
    random.highlighted=NO;
+2  A: 

Try:

UIButton *random = (UIButton *)[self.view viewWithTag:333];

Also, why are you assigning the tag after you have released the button?

pheelicks
Thanks, your code got rid of my warning. The whole retain / release thing shouldnt of been there.Even though I am now successfully getting at the button I cant seem to changed its state to "highlighted". I try to do this in the handler for a UIControlEventTouchUpInside event.Basically I have 3 buttons that I'm trying to implement a toggle effect on. Only one button appears selected at a time
dubbeat