OK, here is my question. For example, I create UISwitch in the first 3-seater accessory.
theSwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
[cell addSubview:theSwitch];
cell.accessoryView = theSwitch;
and add 2 sliders in the next 3 cells
theSlider = [[[UISlider alloc] initWithFrame:CGRectMake(174,12,120,23)] autorelease];
theSlider.maximumValue=99;
theSlider.minimumValue=0;
[cell addSubview:theSlider];
cell.accessoryView = theSlider;
after that, I add an action to switch and slider
[(UISwitch *)cell.accessoryView addTarget:self action:@selector(switchToggled:) forControlEvents:UIControlEventValueChanged];
[(UISlider *)cell.accessoryView addTarget:self action:@selector(sliderValueChange:) forControlEvents:UIControlEventValueChanged];
It works if you only add a switch to the cell
I think it's possible mine @selector(switchToggled:)and@selector(sliderValueChange:)
Question.
if I switch UISwitch it will not work
but if I touch any slider, it crashes and receives a message: "[UISlider isOn]: unrecognized selector sent to the instance"
here is my emptiness about
- (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 {
...
}
}
the sliderValueChangesame as
- (void)sliderValueChange:(id)sender{
UISlider *theSlider = (UISlider *)sender;
UITableViewCell *cell = (UITableViewCell *)theSlider.superview;
UITableView *tableView = (UITableView *)cell.superview;
...
}
Does anyone know how to give action to both controllers?
Many thanks!