Objective c 在另一个UIViewController中禁用UIButton

Objective c 在另一个UIViewController中禁用UIButton,objective-c,uiviewcontroller,ios5,uibutton,Objective C,Uiviewcontroller,Ios5,Uibutton,我想在另一个ViewController的UITableview中禁用UIButton: 我尝试过,在SecondViewController中,但它只禁用了_buttonDesc,buttonCell仍然处于启用状态: buttonCell是UITableView中的按钮 buttonDesc是位于SecondViewController内的按钮Compar 您需要一个要禁用的实际按钮的引用。创建LivroCell的新实例对您没有帮助 最简单的方法是,当有人单击“Buy”按钮时,您创建新

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

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

  • buttonCell是UITableView中的按钮
  • buttonDesc是位于SecondViewController内的按钮Compar


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


最简单的方法是,当有人单击“Buy”按钮时,您创建新的UIViewController,并传递对Buy按钮的引用(如果“Buy”调用iAction,则将sender传递给您创建的子视图控制器)。因此,在您的子视图控制器上创建一个属性来存储按钮,在执行alloc/init时设置该属性,这样以后很容易禁用。

我不理解您的代码与图像的关系。这可能是由第二个viewController中的“Compar”按钮触发的iAction。什么是'u buttonedesc'和什么是'LivroCell'?您只是实例化了一个
LivroCell
,并将其
buttonCell
设置为禁用。它不存在于任何地方,也不存在于用户界面中。要正确禁用它,您需要获取对
LivroCell
的现有实例的引用,然后像禁用一样禁用它。@HeWas,_buttonedEsc是comparbutton,LivroCell是创建UITableview自定义单元格的类。
-(IBAction)comprar
{
    [_buttonDesc setTitleColor:[UIColor grayColor] forState:UIControlStateDisabled];
    [_buttonDesc setEnabled:NO];
    LivroCell *lvc = [[LivroCell alloc]init];

    [lvc.buttonCell setEnabled:NO];
}