好的,这是我的问题示例,我在前 3 个单元格的附件视图中创建了一个 UISwitch
theSwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
[cell addSubview:theSwitch];
cell.accessoryView = theSwitch;
并在接下来的 3 个单元格中添加 2 个滑块
theSlider = [[[UISlider alloc] initWithFrame:CGRectMake(174,12,120,23)] autorelease];
theSlider.maximumValue=99;
theSlider.minimumValue=0;
[cell addSubview:theSlider];
cell.accessoryView = theSlider;
之后,我添加了开关和滑块的动作
[(UISwitch *)cell.accessoryView addTarget:self action:@selector(switchToggled:) forControlEvents:UIControlEventValueChanged];
[(UISlider *)cell.accessoryView addTarget:self action:@selector(sliderValueChange:) forControlEvents:UIControlEventValueChanged];
只要在单元格中添加开关就可以了
我想这也许是我的@selector(switchToggled:)
和@selector(sliderValueChange:)
问题。
如果我切换 UISwitch ,它不会崩溃
但如果我触摸任何滑块,它会崩溃并收到消息:“[UISlider isOn]: unrecognized selector sent to instance”
这是我的空虚
- (void)switchToggled:(id)sender{
UISwitch *theSwitch = (UISwitch *)sender;
UITableViewCell *cell = (UITableViewCell *)theSwitch.superview;
UITableView *tableView = (UITableView *)cell.superview;
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
if(theSwitch.on) {
...
}
else {
...
}
}
最sliderValueChange
一样的
- (void)sliderValueChange:(id)sender{
UISlider *theSlider = (UISlider *)sender;
UITableViewCell *cell = (UITableViewCell *)theSlider.superview;
UITableView *tableView = (UITableView *)cell.superview;
...
}
有谁知道如何给两个控制器一个动作?
十分感谢!