Using the fantastic posts in this forum, I created the switch as an auxiliary element in the tableView. When the switch is switched, my action (switchChanged) is called. Only the sender has a valid value, the event is 0x0.
Adding a target to switchView:
[switchView addTarget:self action:@selector(switchChanged:forEvent:) forControlEvents:(UIControlEventValueChanged | UIControlEventTouchDragInside)];
Act:
- (void) switchChanged:(id)sender forEvent:(UIEvent *)event {
if(event) {
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:[[[event touchesForView:sender] anyObject] locationInView:self.tableView]];
IFDFlightlogFormQuestions *question = [self.resultsController objectAtIndexPath:indexPath];
NSLog(@"IFDNewFlightlogViewController_Pad:switchChanged Switch is %@ xmlAttrib %@",[sender isOn],question.XmlAttrib);
[self.xmlResults setValue:([sender isOn])?@"true":@"false" forKey:question.XmlAttrib];
}
}
Usage action:@selector(switchChanged: forEvent:)- Added space - no change.
Usage action:@selector(switchChanged::)- deleted forEvent- unrecognized selector.
My goal is to get indexPath in a tableView so that I can change the value in my dictionary.
My current workaround is to use only the sender information, but I need the event information:
- (void) switchChanged:(id)sender forEvent:(UIEvent *)event {
UISwitch *switchView = (UISwitch *)sender;
UITableViewCell *cell = (UITableViewCell *)switchView.superview;
UITableView *tableView = (UITableView *)cell.superview;
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
IFDFlightlogFormQuestions *question = [self.resultsController objectAtIndexPath:indexPath];
NSLog(@"IFDNewFlightlogViewController_Pad:switchChanged Switch is %@ xmlAttrib %@",([sender isOn])?@"On":@"Off",question.XmlAttrib);
[self.xmlResults setValue:([sender isOn])?@"true":@"false" forKey:question.XmlAttrib];
}
Any pointers to getting event information about this?