使用这个论坛中的精彩帖子,我在 tableView 中创建了一个开关作为附件视图。当触摸开关时,我的动作(switchChanged)被调用。只有发送者有一个有效值,事件是0x0。
将目标添加到 switchView:
[switchView addTarget:self action:@selector(switchChanged:forEvent:) forControlEvents:(UIControlEventValueChanged | UIControlEventTouchDragInside)];
那个行动:
- (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];
}
}
使用action:@selector(switchChanged: forEvent:)
- 增加空间 - 没有变化。
使用action:@selector(switchChanged::)
- 移除forEvent
- 无法识别的选择器。
我的目标是获取 tableView 的 indexPath,以便我可以更改字典中的值。
我目前的解决方法是只使用发件人信息,但我想要事件信息:
- (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];
}
有关获取有关此事件信息的任何指示吗?