0

我想在单击开关时获取事件,因为我进行了如下编码,但我得到的事件始终为空。问题是什么?我们怎样才能实现?

UISwitch *simpleSwitch = [[UISwitch alloc] initWithFrame:(CGRect){ CGPointZero, { self.frame.size.width, self.frame.size.height }}];
        [simpleSwitch addTarget:self action:@selector(eventHandler:event:) UIControlEventValueChanged];
        [self addSubview:simpleSwitch];

#pragma mark -  handler event methods
- (void)eventHandler:(id)sender event:(UIEvent *)event  {
    NSLog(@"Event type: %@",[event class]);
}
4

0 回答 0