【发布时间】:2017-11-27 08:25:40
【问题描述】:
我在UITableView中有一个UISwitch,我想通过如下方式传递事件,但是事件是nil。如果我为按钮更换了开关,事件就会存在
[switch addTarget:self action:@selector(switchTaped:event:) forControlEvents:UIControlEventValueChanged];
-(void)switchTaped:(id)sender event:(id)event {
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:_tableView];
NSIndexPath *indexPath= [_tableView
indexPathForRowAtPoint:currentTouchPosition];
NSLog(@"%ld",indexPath.row);
}
【问题讨论】:
-
你在哪里使用你的代码来添加动作到开关?