开发者

Simple slider app, quick question

Everything looks right, and yet something is missing. Could you please take a look?

.m

@synthesize textLabel;
@synthesize slider;

- (IBAction)setLabel:(id)sender {
   int res = [slider value]; 
   NSLog(@"something changed %d", res);

[textLabel setText:[NSString stringWithFormat:@"%d",[slider value]]];
}

.h

@interface SlidaAppDelegate : NSObject {
    UILabel *textLabel;
    UISlider *slider;
    NSString *text;
}

- (IBAction)setLabel:(id)sender;

@property (nonatomic, retain) IBOutlet UIWindow *window; 
@property (nonatomic, retain) IBOutlet UILabel *textLabel;
@property (nonatomic, retain) IBOutlet UISlider *slider;

Whenever slider moves, i see value update correctly, however simulator shows strange numbers

Simple slider app, quick question

Simulator shows

Simple slider app, quick question

Simple slider app, quick question

Xib setup is as follows:

Simple slider app, quick question

Please advise

*UPDATE <---------------------------------------- *

Problem went away when i changed

[textLabel setText:[NSString stringWithFormat:@"%d",[slider value]]];

to

[textLabel setText:[NSString s开发者_JAVA百科tringWithFormat:@"%d",res]];

I don't fully understand why that it though, considering that

int res = [slider value]; 

If possible, please explain


My bet is that value returns a float which is in between 0 and 1. So when you assign it to an int, it gets rounded down to 0.

Make res a float.

EDIT

%d wants an int, you were giving it a float with [slider value]. So it must have interpreted that value in a strange way. See DOC

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜