Note that there are some explanatory texts on larger screens.

plurals
  1. POSave and load the image of a button in my iPhone app
    primarykey
    data
    text
    <p>Ok so I i am trying to make the user pick an image from the iphone photos and save that image as an image on a button. When the user shuts down the app and opens it again I want the user to see his saved image again :) theButton contains the sender of which button is clicked btw.</p> <p>I can do the part where the user can put the image as the button image. I use this line to set the image</p> <pre><code>[theButton setImage:btnImage forState:UIControlStateNormal]; </code></pre> <p>Now I am wondering how can I access that image of the button? So I can save and load it?</p> <p>I use this code according to a tutorial but I am stuck with the load part because apparently I do not have to use Imageview because it is only readable :) My code for that:</p> <pre><code>//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]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload