I have been playing around with Xcode lately and am stuck at this stupid problem. Need help!
Okay I added 69 images to supporting files names 1.jpg,2.jpg…69.jpg. They are named so because a loop will be used to create an animation by displaying a series of images. Here is what i did.
Header file:
#import <UIKit/UIKit.h>
@interface myBitchViewController : UIViewController{
NSMutableArray *images;
}
@property (retain, nonatomic) NSMutableArray *images;
@end
And implementation file:
#import "myBitchViewController.h"
@implementation myBitchViewController
@synthesize images;
- (void)viewDidLoad {
for (int imagenumber = 1; imagenumber <= 69; imagenumber++) {
NSMutableString *myString = [NSMutableString stringWithFormat:@"%i", imagenumber];
[myString stringByAppendingString:@".jpg"];
[images addObject:[UIImage imageNamed:myString]];
}
CGRect frame = CGRectMake(0.0, 0.0, 320.0, 460.0);
UIImageView *imageview = [[UIImageView alloc] initWithFrame:frame];
imageview.animationImages = images;
imageview.contentMode = UIViewContentModeScaleAspectFit;
imageview.animationDuration = 3;
imageview.animationRepeatCount = 0;
[imageview startAnimating];
[self.view addSubview:imageview];
[imageview release];
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
Now the issue is that the program doesn’t throw any error but when simulator runs it just shows blank grey screen instead of animation. Where am I going wrong?
It could just be that your
NSMutableArray* images;is never created. By the way, it doesn’t need to be a property, you should create it just as a local variable inviewDidLoad– otherwise you’ll keep adding more and more images to it each time the view loads.