0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

iOS switch ON/OFFでメニューの表示/非表示を切り替えるにはどうしたらいいですか?

Posted at

アプリ作成もプログラミングも初心者です。
先日から勉強を開始しました。
UI何たらのそれぞれの説明は理解できるのですが、それを合わせて利用したい時などの処理がわかりません。本にも書いてなくて困っています。

iPhoneの無線設定のような、on/offの切り替えに伴って表示/非表示が切り替わるようにしたいんですが、どうしたら良いのでしょうか?
例えばonにしたら、それまで非表示だったスライダーが表示されるような感じにしたいです。

現状は以下のようになっています。※色々試しているのでめちゃくちゃですが…。

『ViewController.h』
@interface ViewController : UIViewController

  • (IBAction)mybtn:(id)sender;
    @property (weak, nonatomic) IBOutlet UISwitch *myswh;
  • (IBAction)myswhchg:(id)sender;
    @property (weak, nonatomic) IBOutlet UISlider *slid;
  • (IBAction)chgslid:(id)sender;
    @property (weak, nonatomic) IBOutlet UILabel *mylabel;

@end

『ViewController.m』
@implementation ViewController

  • (void)viewDidLoad
    {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    }

  • (void)didReceiveMemoryWarning
    {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }

  • (IBAction)mybtn:(id)sender {
    NSString *mysld = self.mylabel.text;
    NSLog(@"たっぷした%@",mysld);
    }

  • (IBAction)myswhchg:(id)sender {
    if (self.myswh.on == YES){
    NSLog(@"おん");
    }else{
    NSLog(@"おふ");
    }
    }

  • (IBAction)chgslid:(id)sender {
    self.mylabel.text = [NSString stringWithFormat:@"%.0f", self.slid.value];
    }
    @end

.mファイルでif文を使ってon/offの切り替え時にそれぞれ違った処理を書くところまではわかりました。
if文の中にUIsliderなどは入れられないのでしょうか??

教えてください。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?