我正在我的 uiactionsheet 中实现 Uiswitch,我已经成功地将它放置在我想要的位置,但无法使用它。这是我的代码:
switchButton = [[UISwitch alloc] init];
[mySheet addSubview:switchButton];
[mySheet showInView:self.view];
UILabel *instruction = [[UILabel alloc] init];
[instruction setBackgroundColor:[UIColor clearColor]];
[instruction setText:@"Daily"];
[mySheet addSubview:instruction];
// get the dimension of the sheet to position the switch
CGSize parentSize = mySheet.frame.size;
CGRect rect = switchButton.frame;
rect.origin.x = parentSize.width/2.0 - rect.size.width + 90;
rect.origin.y = parentSize.height - rect.size.height + 90 ;
switchButton.frame = rect;
//get the dimension of the sheet to possition the label
rect.origin.x = parentSize.width/2.0 - rect.size.width -20;
rect.origin.y = parentSize.height - rect.size.height + 90 ;
instruction.frame = rect;
我已经将我的开关按钮初始化为一个 iboutlet。在操作表的功能中,我正在尝试这样做。
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex{
switch (buttonIndex) {
case 0:
{
NSLog(@"Yes Button is working");
}
break;
case 1:
{
if(switchButton.on){
NSLog(@"IS on ?");
}
else {
NSLog(@"Is off?");
}
}
default:
break;
}
**IMP 我还尝试了更多我为它创建“-(ibAction)funct”的东西,但是当我这样做时,我无法将它与我的开关链接起来 **