使用标记属性IPhone获取UIButton

dub*_*eat 5 tags iphone cocoa-touch uibutton uikit

我在使用tag属性访问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;
Run Code Online (Sandbox Code Playgroud)

然后在代码中我尝试以下面的方式获取按钮,这给了我一个错误的说法

不兼容的Objective-C类型初始化'struct UIView*',期望'struct UIButton*'

UIButton *random = [self.view viewWithTag:333];
    random.highlighted=NO;
Run Code Online (Sandbox Code Playgroud)

phe*_*cks 23

尝试:

UIButton *random = (UIButton *)[self.view viewWithTag:333];
Run Code Online (Sandbox Code Playgroud)

另外,为什么在释放按钮后分配标签?