Creating a UISwitch Programmatically

前端 未结 2 1354
鱼传尺愫
鱼传尺愫 2020-12-29 03:07

In a seemingly never ending effort to learn more about iphone development, I have been playing around with some of the source code available through apples developer website

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-29 03:46

    Steve, I'm sorry if I misunderstood your question. Did you actually create the UISwitch and add it to the view hierarchy? Your controller's -loadView or -viewDidLoad implementation should have code like the following:

    // Use the ivar here
    onoff = [[UISwitch alloc] initWithFrame: CGRectZero];
    [onoff addTarget: self action: @selector(flip:) forControlEvents: UIControlEventValueChanged];
    // Set the desired frame location of onoff here
    [self.view addSubview: onoff];
    [onoff release];
    

提交回复
热议问题