、 、および がUIView
ファイルUILabel
内UISlider
に配置されてUIVeiwController
いViewController
ます。また、デバッグ ツールとしてをプログラムで に追加しましたUILabel
。UIView
はい、他の接続と同じように接続できUILabel
ますが、この問題を解決したら、グラフ計算でこの値を渡します。この変数を my に渡すための提案は自由ですが、グローバル変数の作成は避けたいと思います。必要に応じて配置された値に値を渡していますが、実装ファイルのスライダー値を「参照」して値を送信しようとすると、値が送信されず、値がゼロになります。UIView
UILabel
UIView
UISlider
UILabel
UIVeiwController
GraphView.m
私は 2 日間、stackoverflow フォーラムを精査し、ドキュメントを確認し、本を読み直して自分の問題を理解しようとしましたが、多くのことを学びました (そして他の問題を修正しました) が、私はまだこれを理解していません. 私はそれがとても単純なものだと確信しており、私は自分自身を蹴るだろうと確信しています. 他のドキュメントへの参照を歓迎します (おそらく既に読んでいます) が、建設的なフィードバックと方向性も提供してください。私のコードは以下の通りです:
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
NSString *viewControllerSliderValue;
}
- (NSString *) viewConrtollerSliderValue;
@property (weak, nonatomic) IBOutlet UILabel *sliderValueLabel;
@property (weak, nonatomic) IBOutlet UISlider *sliderValue;
- (IBAction)sliderChange:(UISlider *)sender;
@end
ViewController.m
#import "ViewController.h"
#import "GraphView.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
float sliderVal = self.sliderValue.value;
self.sliderValueLabel.text = [NSString stringWithFormat:@"%.1f",sliderVal];
NSLog(@"viewDidLoad: sliderVal = %f", sliderVal);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)sliderChange:(UISlider *)sender
{
float sliderVal = sender.value;
self.sliderValueLabel.text = [NSString stringWithFormat:@"%.1f", sliderVal];
NSLog(@"sliderChange: sliderVal = %f", sliderVal);
}
- (NSString *)viewConrtollerSliderValue
{
float sliderVal = self.sliderValue.value;
viewControllerSliderValue = [NSString stringWithFormat:@"%f",[self sliderValue].value];
NSLog(@"sliderChange: sliderVal = %f", sliderVal);
return viewControllerSliderValue;
}
@end
GraphView.h
#import <UIKit/UIKit.h>
@interface GraphView : UIView
@end
GraphView.m
#import "GraphView.h"
#import "ViewController.h"
@implementation GraphView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect
{
ViewController *viewController = [[ViewController alloc] init];
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 90, 140, 20)];
NSLog(@"GraphView: drawRect: vierContrllerSliderValue = %@", [viewController viewConrtollerSliderValue]);
myLabel.text = [viewController viewConrtollerSliderValue];
myLabel.backgroundColor = [UIColor lightGrayColor];
myLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:myLabel];
}
@end