ユーザーがボタンをタップしたときにUISwitchと完了ボタンを含むポップを表示し、ポップアップの完了ボタンがタップされたときにスイッチの状態を保存する必要があります。
だから私はこれを行うためにUIActionSheetを使用します -
sheet = [[UIActionSheet alloc] initWithTitle:@"Switch Setting"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:@"Done", nil];
theSwitch = [[UISwitch alloc] init];
[sheet addSubview:theSwitch];
[sheet showInView:self.view];
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == actionSheet.firstOtherButtonIndex)
{
theSwitch .on? NSLog(@"Switch is on") : NSLog(@"Switch if off");
}
}
これはすべてうまくいきます。ポジショニングに問題があります。残念ながら、現時点ではここに投稿するスクリーン ショットがありません。ただし、スイッチはアクション シートのタイトルと同じ行の一番上に表示され、その下に [完了] ボタンがあります。
スイッチをタイトルの下に配置し、アクション シートのサイズを大きくして見栄えを良くする方法を教えてください。早急にこれが必要です。ありがとう。