gpt4 book ai didi

ios - 为什么我点击 UISwitch ,它不起作用?

转载 作者:行者123 更新时间:2023-11-29 13:08:06 34 4
gpt4 key购买 nike

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];

if (self) {
self.sw = [[[UISwitch alloc] initWithFrame:CGRectMake(210, 8, 50, 30)] autorelease];
[sw setOn:YES];
[sw addTarget:self action:@selector(switchChanged) forControlEvents:UIControlEventTouchUpInside];

[self addSubview:sw];
}

return self;
}

-(void)switchChanged
{
// [self setImage];
[sw setOn:NO];
if (_delegate && [_delegate respondsToSelector:@selector(selectedWith:)]){
[_delegate selectedWith:self];
}
}

当我点击开关时,函数switchChanged没有被调用?

最佳答案

forControlEvents 更改为 UIControlEventValueChanged 而不是 UIControlEventTouchUpInside

试试这个,

 [sw addTarget:self action:@selector(switchChanged) forControlEvents:UIControlEventValueChanged];

关于ios - 为什么我点击 UISwitch ,它不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18096455/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com