Saving UIColor on Exit


i trying save uicolor nsmutabledictionary other items when use button my navcontroller. saves , loads again when click on button create viewcontroller plist file except uicolor 'null'? added nslogs see happening.

if delete plist , start fresh here happens. method checks plist file , creates if not there, or loads information.
code:
- (void)readplist{      nsstring *filepath = [self datafilepath];      if([[nsfilemanager defaultmanager] fileexistsatpath:filepath])      {          savedlist = [[nsmutabledictionary alloc] initwithcontentsoffile:filepath];                              nsarray *temparray = [[nsarray alloc] initwitharray: [savedlist objectforkey:@"monthly"]];          checknumbers = [[nsmutablearray alloc] initwitharray: temparray copyitems:yes];          [temparray release];                                        nsarray *temparraytwo = [[nsarray alloc] initwitharray: [savedlist objectforkey:@"total"]];          totalpayments = [[nsmutablearray alloc] initwitharray: temparraytwo copyitems:yes];          [temparraytwo release];                              nsarray *temparraythree = [[nsarray alloc] initwitharray: [savedlist objectforkey:@"item"]];          nslog(@"temparraythree %@", temparraythree);          clientlist = [[nsmutablearray alloc] initwitharray: temparraythree copyitems:yes];          [temparraythree release];                              [color="red"]cgcolorref tmpcolor = [[savedlist objectforkey:@"backgroundcolor"] cgcolor];          nslog(@" temp color loaded %@",[savedlist objectforkey:@"backgroundcolor"]);          backdropcolor = [[uicolor alloc] initwithcgcolor:tmpcolor];          [color="blue"]nslog(@"color loaded %@", backdropcolor);[/color][/color]      }       else{          savedlist = [[nsmutabledictionary alloc] init];          [savedlist writetofile: filepath atomically:yes]; // if can't find it, writes blank file.          nslog(@"no plist on file - created new one");          checknumbers = [[nsmutablearray alloc] init];          totalpayments = [[nsmutablearray alloc] init];          clientlist = [[nsmutablearray alloc] init];         [color="red"] backdropcolor = [[uicolor alloc] initwithred: 0.7 green:0.7 blue:0.7 alpha:1.0];[/color]          [color="blue"]nslog(@"background color load:%@ ", backdropcolor);[/color]      }  }  
when write plist have nslog checks see going saved.

code:
- (void)writeplist{         [color="blue"] nslog(@"background color saved:%@ ", backdropcolor);[/color]      [savedlist setobject:clientlist forkey:@"item"];      [savedlist setobject:checknumbers forkey:@"monthly"];      [savedlist setobject:totalpayments forkey:@"total"];      [color="red"][savedlist setobject: backdropcolor forkey:@"backgroundcolor"];[/color]      [savedlist writetofile:[self datafilepath] atomically:yes];     }  
the console print out nslog
but when try reload returning 'null'
code:
cgcolorref tmpcolor = [[savedlist objectforkey:@"backgroundcolor"] cgcolor];          [color="red"]nslog(@" temp color loaded %@",[savedlist objectforkey:@"backgroundcolor"]);[/color]          backdropcolor = [[uicolor alloc] initwithcgcolor:tmpcolor];          nslog(@"color loaded %@", backdropcolor);  
what on looking?
 

memory management weak spot, think issue: never call retain on color when back. try this:

code:
cgcolorref tmpcolor = [[[savedlist objectforkey:@"backgroundcolor"] cgcolor] retain];
 


Forums iPhone, iPad, and iPod Touch iOS Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

Comments

Popular posts from this blog

Mac OS X Server as File Server for 50/50 Mac & PC Workgroup

Permissions Problem?

iPhone won't sync with iTunes