I'm an Xcode beginner, and am trying to make certain programs for practice. I've tried to make a program which would act like a story book.
It has a View and a Button. It would show a picture from an array in the View, and when the Button is pressed, it would go to the next picture in the array. However, nothing is showing up when I launch it. Not even the Button.
Here is my code:
.h:
.m:
Does anybody know why this would be?
It has a View and a Button. It would show a picture from an array in the View, and when the Button is pressed, it would go to the next picture in the array. However, nothing is showing up when I launch it. Not even the Button.
Here is my code:
.h:
Code:
#import <UIKit/UIKit.h>
@interface PictureBookViewController : UIViewController{
//instance variables
__strong IBOutlet UIImageView *myPicturePage;
__strong IBOutlet UIButton *nextButton;
NSArray *pictureBookImages;
int currentPage;
bool notLastPage;
}
//properties
//free up memory for delivering stuff to outlets
@property (retain, nonatomic)UIImageView *myPicturePage;
@property (retain, nonatomic)NSArray *pictureBookImages;
@property (retain, nonatomic)UIButton *nextButton;
//methods
- (IBAction)next:(id)sender;
@end
.m:
Code:
#import "PictureBookViewController.h"
@interface PictureBookViewController ()
@end
@implementation PictureBookViewController
@synthesize myPicturePage;
@synthesize nextButton;
@synthesize pictureBookImages;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
notLastPage = TRUE;
currentPage = 0;
pictureBookImages = [[NSArray alloc] initWithObjects:
[UIImage imageNamed: @"Cat1.png"],
[UIImage imageNamed: @"Cat2.png"],
[UIImage imageNamed: @"Cat3.png"],
nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)next:(id)sender {
currentPage++;
if(notLastPage){
[nextButton setTitle: @"Next" forState: UIControlStateNormal];
}
else{
[nextButton setTitle: @"Restart" forState: UIControlStateNormal];
}
if(currentPage >= [pictureBookImages count]){
currentPage = 0;
}
[UIImage animatedImageNamed:@"turnpage" duration:1];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut],
notLastPage = YES;
if(currentPage == 1){
[UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:(self.view) cache:(YES)],
notLastPage = NO;
}
if(currentPage == 2){
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES],
[UIView commitAnimations],
notLastPage = NO;
myPicturePage.image = [pictureBookImages objectAtIndex:currentPage];
}
}
@end
Does anybody know why this would be?
Last edited: