getting at a UIButton with the tag property IPhone

Posted by dubbeat on Stack Overflow See other posts from Stack Overflow or by dubbeat
Published on 2010-05-10T13:10:03Z Indexed on 2010/05/10 13:14 UTC
Read the original article Hit count: 1433

Filed under:
|
|

Hey There,

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

UIButton   *randomButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect ]retain];    
    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 release];
    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;

© Stack Overflow or respective owner

Related posts about uibutton

Related posts about cocoa