私は2つのViewControllerを持っています。
FirstViewController には UILabels と UIImageViews があります。また、そのクラスからシングルトンを生成しました。SecondViewController にはそのシングルトンの呼び出しがあり、FirstViewController から UILabels と UIImageViews の値を取得する必要があります。
NSString は機能しますが、UILabel は機能しません。
たとえば、「sharedFirstViewController.nsstringvarname 」を使用して SecondviewController のNSStringにアクセスし、値を GET および SET できます。 これはうまくいきます!
「 sharedFirstViewController.uilabelvar.text 」のようなUILabelで同じことを試してみてください。この UILable の値を SET または GET することはできません。 これは機能しません。
UI オブジェクトに何か特別なことはありますか? 誰かがそれで私を助けることができれば素晴らしいでしょう. ありがとう!
編集:
FirstViewController.h で
+ (id)sharedFirstViewController;
@property (copy, nonatomic) NSString *path;
@property (strong, nonatomic) IBOutlet UIImageView *pic;
FirstViewController.m 内
@synthesize path= _path;
@synthesize pic = _pic;
- (id)init {
if (self = [super init]) {
_pic = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 200)];
}
return self;
}
+ (id) sharedFirstViewController {
static sharedFirstViewController * sharedFirstViewController = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedFirstViewController = [[self alloc] init];
});
return sharedFirstViewController;
}
SecondViewController.m で
#import "FirstViewController.h"
- (void)viewDidLoad
{
FirstViewController * sharedFirstViewController = [FirstViewController sharedFirstViewController];
NSLog(@"this is NSString from FVC: %@" sharedFirstViewController.path); //works
UIImage * picture = [UIImage imageWithContentsOfFile:sharedFirstViewController.path];
sharedFirstViewController.pic.image = picture; // does´t work
}