xcode - Change a loaded image based on a NSUserDefaults setting -



xcode - Change a loaded image based on a NSUserDefaults setting -

hope can help me this. have app needs show 1 of 2 maps via setting of uiswitch. settings.bundle set , trying write if statement determine if switch on or off, , display right image.

nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults]; bool enabled = [defaults boolforkey:@"zones_preference"]; if (enabled == @"enabled") { [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"withzones.jpg"]]; } else { [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"withoutzones.jpg"]]; }

this builds without error, doesn't load image scrollview. advise on going wrong?

well, code you've posted creates uiimageview object , doesn't more. it's leak too.

there's 1 more error in line

if (enabled == @"enabled") {

here, comparing boolean string evaluate false automatically needs corrected too.

nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults]; bool enabled = [defaults boolforkey:@"zones_preference"]; uiimageview * imageview; if ( enabled ) { imageview = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"withzones.jpg"]]; } else { imageview = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"withoutzones.jpg"]]; } imageview.frame = imageviewframe; // "imageviewframe" appropriate frame. [scrollview addsubview:imageview]; [imageview release];

xcode

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -