iphone - iOS - 无法设置按钮 'Disable' ,而不删除其内容

标签 iphone objective-c ios xcode ipad

抱歉,这应该是一个简单的解决方案。

我正在尝试使用以下代码“禁用”代码中的按钮:

在第一个名为“CheckBox”的类中:

checkBox.h:

@interface CheckBox : UIViewController 
{   
   BOOL checkboxSelected;
   UIButton *checkBoxButton;
}

 @property (nonatomic, retain) IBOutlet UIButton *checkBoxButton;


- (IBAction)checkBoxButton:(id)sender;


-(void) setCheckBoxSelected:(BOOL)checkingStatus;
-(void) setCheckBoxEnabled:(BOOL)enablingStatus;

在 checkBox.m 中:

- (IBAction)checkBoxButton:(id)sender {

if (checkboxSelected == 0){
    [checkBoxButton setSelected:YES];
    checkboxSelected = 1;

} else {

    [checkBoxButton setSelected:NO];
    checkboxSelected = 0;
      }
}

 -(void) setCheckBoxSelected:(BOOL)checkingStatus {

   checkBoxButton.selected = checkingStatus;
     }

 -(void) setCheckBoxEnabled:(BOOL)enablingStatus {

    [checkBoxButton setEnabled:enablingStatus];
   }

以及另一个名为“MainViewController.m”的类的实现:

- (void)viewDidLoad{

     allTransactionCheckBox = [[CheckBox alloc] init];
     [self.viewWithdraw addSubview:withdrawCheckBox.view ]; 
     withdrawCheckBox.labelCheckBox.textColor = [UIColor blackColor];
     withdrawCheckBox.labelCheckBox.font = [UIFont systemFontOfSize:14];
     withdrawCheckBox.labelCheckBox.text = @"Withdraw";   

     [withdrawCheckBox setCheckBoxSelected:YES];
 }

上面的代码是“禁用”按钮,但它(删除/隐藏)按钮内的“复选标记图片”。为什么?

所有链接(outlet + Actions)均已连接。

我错过了什么明显的事情?谢谢。

最佳答案

你到底想做什么?也许设置 userInteractionEnabled 就是您想要的? 干杯

关于iphone - iOS - 无法设置按钮 'Disable' ,而不删除其内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9928948/

相关文章:

ios - 将NSString传递给UInt8 []

ios - 将字符串转换为运算符 - swift

iphone - 即使在静音模式下也能在 iPhone 上播放声音

iPhone Storyboard导航

ios - 将 View Controller 保持在与左侧相同的位置

iphone - 如何处理 UITableView 或 ScrollView 等触摸事件

ios - 如何为 CALayer 使用基于 block 的动画?

iphone - 德语字符显示不正确

iphone - 从 Facebook 应用程序发布后返回自己的应用程序

ios - 如何提示编译器使用 UIView 子类