在UITableViewCell中将UIButton转换为自定义类不起作用

时间:2015-08-24 16:16:03

标签: ios objective-c uitableview uibutton

我创建了一个自定义切换按钮类,它继承自UIButton。我在故事板上将按钮添加到UITableViewCell,并在Identity Explorer的Custom - >中分配了类“LmxStartStopToggleButton”。课程部分。对于UITableViewCell,我创建了一个自定义类“LmxRijtijdTableViewCell”并按住Ctrl键拖动到IBOutlet“rijtijdBtn”

@property IBOutlet LmxStartStopToggleButton *rijtijdBtn;
这个类的@interface。一切正常。 但之后我想在初始化时从UITableViewCell内部操纵按钮的外观。运行时它似乎不是“LmxStartStopToggleButton”类型,但类型为UITableViewCellContentType,我无法转换为它。如果无法投射按钮,如何调用按钮上的函数?或者,如果我在Identity Explorer中设置它,为什么最初的类型不正确?

LmxStartStopToggleButton *btn = ((LmxStartStopToggleButton *)self.rijtijdBtn); 

enter image description here

1 个答案:

答案 0 :(得分:1)

确保您的单元格中没有其他元素指向" rijtijdBtn。"

如果这不是问题,请确保该按钮的类型为" LmxStartStopToggleButton"单击界面编辑器中的按钮,转到右侧工具栏右侧的第3个选项卡,然后确保在" Custom Class"它说" LmxStartStopToggleButton。"

相关问题