change image from array on uiimageview

Discussion in 'iOS Programming' started by uncleunvoid, Oct 26, 2010.

  1. uncleunvoid macrumors newbie

    Feb 19, 2005
    Hi , I am fairly new as you will be able to tell in about a few characters.

    I am trying to do a simple image animation with an array containing my images.

    The code runs. but the app in the iphone tester closes itself(crashes?) after less than a second without any error hint.

    I am declaring the nsarray and uiimageview like this:

    @class NSArray;
    @interface NSTimerDemoViewController : UIViewController 
    	int animationFrame;
    	UIImageView *imageView;
    	NSArray *locList;
    	UIImage *newImage;
    	NSTimer *myTimer;
    	CLLocationManager *locationManager;
    @property (nonatomic, retain) IBOutlet UIImageView *imageView;
    @property (nonatomic, retain) IBOutlet NSArray *locList;
    @property (nonatomic, retain) IBOutlet UIImage *newImage;

    - (void)viewDidLoad 
        [super viewDidLoad];
    	locList = [NSArray arrayWithObjects:
    			   [UIImage imageNamed:@"1.png"],
    			   [UIImage imageNamed:@"2.png"],
    			   [UIImage imageNamed:@"3.png"], nil];
    	imageView.image = [UIImage imageNamed:@"2.png"];
    	//imageView.animationImages = locList;	
    	//imageView.animationDuration = 3;
    	//imageView.animationRepeatCount = 0;
    	//[imageView startAnimating];
    	[self.view addSubview:imageView];
    	animationFrame = 0;
    	myTimer = [NSTimer scheduledTimerWithTimeInterval:1/4 target:self selector:@selector(timeHandler) userInfo:nil repeats:YES];
    	animationFrame = animationFrame + 1;
    		animationFrame = 0;
    	NSLog (@"show stuff %d",animationFrame);
    	imageView.image = [locList objectAtIndex: animationFrame];
    Now i figured out that the error is in the line

    imageView.image = [locList objectAtIndex: animationFrame];
    But I had a bit of a look around and the code looks fine. The locList NSArray seems to somehwo cause trouble, so I know I am fairly close, but just cant get it to work.

  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    If you are going to declare a property, you should make an effort to use the accessors that were synthesized for it. does this; property doesn't (it just uses the ivar).

    P.S. Have you considered using UIImageView's built-in image-animation capabilities?

Share This Page