渡された値を1つだけ含むシングルトンクラスを使用しました。次に、もう1つ追加しようとしました。
#import <Foundation/Foundation.h>
@interface GlobalValueContainer : NSObject {
NSString *passedText;
NSString *myPassedPictureName;
}
@property (nonatomic, strong) NSString* passedText;
@property (nonatomic, strong) NSString* myPassedPictureName;
+ (GlobalValueContainer *) sharedStore;
@end
#import "GlobalValueContainer.h"
@implementation GlobalValueContainer;
@synthesize passedText;
@synthesize myPassedPictureName;
static GlobalValueContainer *sharedStore = nil;
+ (GlobalValueContainer *) sharedStore {
@synchronized(self){
if (sharedStore == nil){
sharedStore = [[self alloc] init];
}
}
return sharedStore;
}
@end
最初のビューから、次に設定しようとしますmyPassedPictureName
-(IBAction)setPicture:(id)sender{
myPicture = @"Hus";
GlobalValueContainer* localContainer = [GlobalValueContainer sharedStore];
localContainer.myPassedPictureName = myPicture;
}
2番目のビューでは、その名前(+ png)でimageviewを設定します
- (void)viewDidLoad
{
[super viewDidLoad];
//Store* myStore = [Store sharedStore];
GlobalValueContainer* localContainer = [GlobalValueContainer sharedStore];
myPassedPictureName = localContainer.myPassedPictureName;
myPicture.image = [UIImage imageNamed:myPassedPictureName];
whatFile.text = myPassedPictureName;
//object.imageView.image = [UIImage imageNamed:@"downloadedimage.png"];
}
写真は表示されません。また、UIlabelを追加して、渡されるはずの文字列を設定しようとしました。しかし、それも空白になります。
「passedText」を使用してテキストを渡すと、正常に機能します。2番目のNSStringを追加しても、何も起こりません。
まず最初に。誰もが何が悪いのかを知ることができますか(まだここでobj cを学習しています:)、それは私がを操作しようとする正しい方法ですかUIImageView
?押しているボタンに応じて、を使っmyPassedPictureName
て何秒も画像を設定したい。UIView
ご意見をお待ちしております。