Ken*_*ent 4 objective-c uitableview uiswitch ios
使用此论坛中的精彩帖子,我在tableView中创建了一个switchView作为accessoryView.当触摸开关时,我的动作(switchChanged)被调用.只有发送方具有有效值,事件为0x0.
将目标添加到switchView:
[switchView addTarget:self action:@selector(switchChanged:forEvent:) forControlEvents:(UIControlEventValueChanged | UIControlEventTouchDragInside)];
Run Code Online (Sandbox Code Playgroud)
那个行动:
- (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];
}
}
Run Code Online (Sandbox Code Playgroud)
使用action:@selector(switchChanged: forEvent:)- 增加空间 - 没有变化.
使用action:@selector(switchChanged::)- 删除forEvent- 无法识别的选择器.
我的目标是将indexPath放到tableView中,这样我就可以更改字典中的值.
我目前的解决方法是仅使用发件人信息,但我想要事件信息:
- (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];
}
Run Code Online (Sandbox Code Playgroud)
有关获取此事件信息的任何指示?
可以@selector通过向目标添加目标来触发UISwitch.
[switchCtl addTarget:self action:@selector(action:) forControlEvents:UIControlEventValueChanged];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9956 次 |
| 最近记录: |