Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

UpsideDown

macrumors newbie
Original poster
Nov 3, 2013
6
0
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:
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:

MattInOz

macrumors 68030
Jan 19, 2006
2,760
0
Sydney
Nothing showing?
For how long?
Do you kill it or does the OS kill it?

Put break points in each method to see if they are they getting called?
Is the memory warming being called?
Can you step through each method as called and make it to the end?
 

UpsideDown

macrumors newbie
Original poster
Nov 3, 2013
6
0
Nothing showing?
For how long?
Do you kill it or does the OS kill it?

Put break points in each method to see if they are they getting called?
Is the memory warming being called?
Can you step through each method as called and make it to the end?

I end up killing it. When I put the breakpoint right on the line of the last curly bracket of

Code:
- (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];
}

it stops and all of the variables seem to be fine. However, when I put it anywhere after that (including the space in the line under the curly), it doesn't ever stop.
 

devilofspades

macrumors member
Jul 20, 2011
76
0
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:
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?

this may sound like a dumb question, but a pretty obvious one. did you wire everything up between your code and interface builder? when you have something like an "IBAction" or "IBOutlet" those are just special typedefs so interface builder knows its a "thing" on the screen or some kind of method / action. even still you need to go through and connect all those manually between your .xib / storyboard and your code. thats what the little "O" on the left side of the outlet or action in xcode is for.

----------

Why do you have an empty interface at the top of the .m file? Does that even compile?

you don't need to have anything in the private interface section. it just means all his variables and methods will all be public. its perfectly fine to have a private interface and just leave it empty. pointless, but acceptable.
 

UpsideDown

macrumors newbie
Original poster
Nov 3, 2013
6
0
this may sound like a dumb question, but a pretty obvious one. did you wire everything up between your code and interface builder? when you have something like an "IBAction" or "IBOutlet" those are just special typedefs so interface builder knows its a "thing" on the screen or some kind of method / action. even still you need to go through and connect all those manually between your .xib / storyboard and your code. thats what the little "O" on the left side of the outlet or action in xcode is for.

----------



you don't need to have anything in the private interface section. it just means all his variables and methods will all be public. its perfectly fine to have a private interface and just leave it empty. pointless, but acceptable.

Yes, I believe so. First of all, I CTRL dragged them in. Also, right clicking on them, it says the right names under "referencing outlets".
 

devilofspades

macrumors member
Jul 20, 2011
76
0
Yes, I believe so. First of all, I CTRL dragged them in. Also, right clicking on them, it says the right names under "referencing outlets".

i see you have a bunch of retains so your're obviously not using arc. am i too take you are not using storyboards either and are using a .xib for you ui? there are lots of factors unfortunately and since it doesn't seem "code" related and more of an issue with the underlying project somewhere. without seeing the whole project, i would suggest starting with a new project and build your ui in interface builder and wire it up and see if that works, then start adding in your code. if you can't even see a button you brought in from ib, there is something amiss with loading your storyboard / .xib. the only thing i can think is if you started with a completely empty project and some how your view / window did not get wired up to your code or you accidentally removed that connection. check your view and see if it has its corresponding outlet tied to its files owner.
 

UpsideDown

macrumors newbie
Original poster
Nov 3, 2013
6
0
i see you have a bunch of retains so your're obviously not using arc. am i too take you are not using storyboards either and are using a .xib for you ui? there are lots of factors unfortunately and since it doesn't seem "code" related and more of an issue with the underlying project somewhere. without seeing the whole project, i would suggest starting with a new project and build your ui in interface builder and wire it up and see if that works, then start adding in your code. if you can't even see a button you brought in from ib, there is something amiss with loading your storyboard / .xib. the only thing i can think is if you started with a completely empty project and some how your view / window did not get wired up to your code or you accidentally removed that connection. check your view and see if it has its corresponding outlet tied to its files owner.
I am using main.storyboard. I deleted all the items in there and remade and reconnected them, but I got the same result. I also made a whole new project and that didn't work either.
 

TheWatchfulOne

macrumors 6502a
Jun 19, 2009
838
972
Would you mind posting the code from your AppDelegate? Particularly this method:

Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 

MattInOz

macrumors 68030
Jan 19, 2006
2,760
0
Sydney
Yes, I believe so. First of all, I CTRL dragged them in. Also, right clicking on them, it says the right names under "referencing outlets".

Have you tried commenting out some of the heavy weight operations to create a simpler starting point for your app and keep pulling it back till it works?

Better still start at the smallest testable point then add piecemeal.

Say instead of loading the png files just change the background colour of the view as the button is pressed. Once you have a simple working base then adding function is a lot easier.
 

UpsideDown

macrumors newbie
Original poster
Nov 3, 2013
6
0
Would you mind posting the code from your AppDelegate? Particularly this method:

Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Sure.

Code:
#import "PictureBookAppDelegate.h"

@implementation PictureBookAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    return YES;
}
							
- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
 

UpsideDown

macrumors newbie
Original poster
Nov 3, 2013
6
0
Resolved

Hey guys, I figured it out, and the problem was really stupid. I think I can safely say it's not my fault though.

So, basically, I chose the 3.5 retina display (only because the emulator window will fit fully on my screen that way), and I intuitively assumed that it would make the storyboard view that size. Turned out, it didn't, and had the view at 4 inches. I didn't see my button because it was near the bottom of the screen.

I fixed this now, sorry that this dumb problem has wasted your time :(
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.