简体   繁体   English

UISlider iPhone SDK问题

[英]UISlider iPhone SDK Question

Okay. 好的。 In Xcode, I want my application to run a line of code once the UISlider gets to 1.00 or the end of the slider. 在Xcode中,我希望我的应用程序在UISlider达到1.00或滑块末端时运行一行代码。 How would I do this? 我该怎么做?

Add these to your UIViewController. 将它们添加到您的UIViewController。

In your .h, below the interface: 在您的.h中,在界面下方:

-(IBAction)sliderChangedValue:(id) sender;

In your .m: 在您的.m中:

-(IBAction)sliderChangedValue:(id) sender {
    if([sender isKindOfClass:[UISlider class]]) {
        UISlider *slider = (UISlider *)sender;
        if(slider.value == 0.0 || slider.value == 1.0) {
            //your line of code
        }
    }
}

Then in Interface Builder connect Value Changed of your UISlider to this method. 然后在Interface Builder中将UISlider的Value Changed连接到此方法。

Write an IBAction method, and connect it to your UISlider in Interface Builder, selecting "On Changed Value" in the dialog that will appear. 编写一个IBAction方法,并将其连接到Interface Builder中的UISlider,然后在出现的对话框中选择“更改后的值”。 Then add some code like this to the method: 然后向该方法添加如下代码:

if(mySlider.value == 1.0f){
    //Insert your code here
}

--James - 詹姆士

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM