English 中文(简体)
Slider Not Behav as I Will Expect
原标题:Slider Not Behaving As I Would Expect

我的先辈将浮标从1到10,但我希望节省这一价值,并在所有观点控制者中加以使用,因此我已把浮标作为NSNumber保留在一个模型类别中(设定Data.sensitativeSliderSettingValue)。

我正试图每改变一次向青少年提供更新的梯度值,但这种数值只是固定在0而不是0到10。 我不理解为什么是......

我的守则如下:

-(IBAction)sensitivitySliderValueChanged:(id)sender
{
    [self updateSensitivity];    
}


-(void)updateSensitivity{


    settingsData.sensitivitySettingValue = [NSNumber numberWithFloat:sensitivitySlider.value];

    NSLog(@"The Slider Value is: %1.1f", [settingsData.sensitivitySettingValue floatValue]);

}
问题回答

我以模拟方式执行了你的整个法典,其运作如下:

页: 1

#import "SliderDemoViewController.h"
#import "SettingsData.h"

@implementation SliderDemoViewController


-(IBAction)sensitivitySliderValueChanged:(id)sender
{
    [self updateSensitivity];    
}

-(void)updateSensitivity{

    settingsData.sensitivitySettingValue = [NSNumber numberWithFloat:sensitivitySlider.value];
    NSLog(@"The Slider Value is: %1.1f", [settingsData.sensitivitySettingValue floatValue]);
    NSLog(@"sensitivitySlider.value= %f",sensitivitySlider.value);
    NSLog(@"sensitivitySlider.minimumValue= %f",sensitivitySlider.minimumValue);
    NSLog(@"sensitivitySlider.maximumValue= %f",sensitivitySlider.maximumValue);
}
@end

页: 1

#import <UIKit/UIKit.h>
@class SettingsData;
@interface SliderDemoViewController : UIViewController {
    IBOutlet    UISlider*   sensitivitySlider;
    SettingsData* settingsData;
}
-(IBAction)sensitivitySliderValueChanged:(id)sender;
@end

现在,SettingsData是宣布为数据模型的一组数据。

页: 1

@interface SettingsData : NSObject {
    NSNumber* sensitivitySettingValue;
}

@property (nonatomic, retain) NSNumber *sensitivitySettingValue;
@end

如今,更新后敏感性的产出也将是这样。

2011-11-22 09:59:57.259 SliderDemo[691:207] The Slider Value is: 0.0
2011-11-22 09:59:57.260 SliderDemo[691:207] sensitivitySlider.value= 5.581448
2011-11-22 09:59:57.261 SliderDemo[691:207] sensitivitySlider.minimumValue= 1.000000
2011-11-22 09:59:57.261 SliderDemo[691:207] sensitivitySlider.maximumValue= 10.000000

如果看一线记录,则总输出0.00,因为我们没有分配的环境。 数据标。

我发现的唯一一点是你可能做一些错误的事情,不是制造这个目标。

if(!settingsData)
{
   settingsData = [[SettingsData alloc]init];
}

除非你分配这个标的,否则你将永远获得0的浮动价值,同时为财产敏感性的价值做一个安全记录仪。 A. 安排 价值。 如果你在某个地方分配了这个物体,那么你在试图确定或收回其任何成员的变数之前,就能够把这个物体分配给你。

Have you NSLogged the raw sensitivitySlider.value to make sure the slider itself is setup correctly?





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...