わかりましたので、ユーザーにiPhoneの写真から画像を選択させ、その画像をボタンの画像として保存しようとしています。ユーザーがアプリをシャットダウンして再度開くと、ユーザーに保存した画像をもう一度表示してもらいたい:) theButtonには、クリックされたボタンの送信者が含まれています。
ユーザーが画像をボタン画像として配置できる部分を行うことができます。この行を使用して画像を設定します
[theButton setImage:btnImage forState:UIControlStateNormal];
ボタンの画像にどのようにアクセスできますか?それで、保存してロードできますか?
私はチュートリアルに従ってこのコードを使用しますが、読み取り専用であるため Imageview を使用する必要がないように見えるため、ロード部分で立ち往生しています:)そのための私のコード:
//SAVE
-(NSString *)pathOfFile{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsFolder = [paths objectAtIndex:0];
return [documentsFolder stringByAppendingFormat:@"myfile.plist"];
}
-(void)applicationWillTerminate:(NSNotification*)notification{
NSMutableArray *array = [[NSMutableArray alloc]init];
[array addObject: tileOne.imageView];
[array addObject: tileTwo.imageView];
[array writeToFile:[self pathOfFile] atomically:YES];
}
//LOAD
- (void)viewDidLoad
{
NSString *filePath = [self pathOfFile];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSArray *array = [[NSArray alloc]initWithContentsOfFile:filePath];
//Here it says read only, what to use then?
tileOne.imageView = [array objectAtIndex:0];
}
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:app];
[super viewDidLoad];
}