得到一个UIButton与标记属性IPhone [英] getting at a UIButton with the tag property IPhone

查看:92
本文介绍了得到一个UIButton与标记属性IPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用标记属性访问UIButton时遇到了一些麻烦

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


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

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



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


推荐答案

尝试:

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

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

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

这篇关于得到一个UIButton与标记属性IPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆