【问题标题】:Disable UIButton in another UIViewController在另一个 UIViewController 中禁用 UIButton
【发布时间】:2013-02-08 16:07:18
【问题描述】:

我想在另一个 ViewController 的 UITableview 中禁用 UIButton:

我在 SecondViewController 中尝试过,但它只禁用了 _buttonDesc,buttonCell 仍然处于启用状态:

  • buttonCell 是 UITableView 内部的 Button。
  • buttonDesc 是 SecondViewController 内的 Button Comprar。

-(IBAction)comprar
{
    [_buttonDesc setTitleColor:[UIColor grayColor] forState:UIControlStateDisabled];
    [_buttonDesc setEnabled:NO];
    LivroCell *lvc = [[LivroCell alloc]init];

    [lvc.buttonCell setEnabled:NO];
}

【问题讨论】:

  • 我不明白您的代码与图像的关系。大概是由第二个 viewController 中的“Comprar”按钮触发的 IBAction。什么是“_buttonDesc”,什么是“LivroCell”?
  • 您只是在实例化一个 LivroCell 并将它的 buttonCell 设置为禁用。它不存在于任何地方,您也不会在您的 UI 中看到它。要正确禁用它,您需要获取对LivroCell现有 实例的引用,然后像您一样禁用它。
  • @HeWas,_buttonDesc 是 ComprarButton,LivroCell 是创建 UITableview 的自定义单元格的类。

标签: objective-c uiviewcontroller ios5 uibutton


【解决方案1】:

您需要对要禁用的实际 buttonCell 的引用。创建一个新的 LivroCell 实例对您没有帮助。

执行此操作的最简单方法是当有人单击“购买”按钮时,您创建新的 UIViewController,传递对购买按钮的引用(如果“购买”调用 IBAction,则将发送者传递给您的子视图控制器创造)。因此,在您的子视图控制器上创建一个属性来存储按钮,在执行 alloc/init 时设置该属性,然后很容易禁用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多