我在uiactionsheet内部实现了Uiswitch,我已经成功地将它放置在我想要的位置,但无法使用它。这里是我的代码:如何从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为)本功能”的,但我这样做时,我无法获得与关联此我的开关**
你的意思是你不能使用开关(不能与它交互)或不能读取正确的值? – M0rph3v5 2013-03-19 14:33:04
我不能读它,实际上如果你看到我的代码在Uiactionsheet当我试图通过switch语句捕获它永远不会返回任何东西:S – 2013-03-19 14:44:25