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

kaz67

macrumors newbie
Original poster
Jan 18, 2011
3
0
I am following a tutorial and everything looks fine in the interface builder and as far as I can tell in the code. When I bring up the simulator in interface builder everything looks correct. When I build and run all I get is a white screen and when I click it acts like a text box and brings up the keyboard.

Code:
//

#import <UIKit/UIKit.h>

@interface OutletsAndActionsViewController : UIViewController {
	//---declaring the outlet---
    IBOutlet UITextField *txtName;
}
//---expose the outlet as a property---
@property (nonatomic, retain) UITextField *txtName;

//---declaring the action---
-(IBAction) btnClicked: (id) sender;

@end

Code:
#import "OutletsAndActionsViewController.h"

@implementation OutletsAndActionsViewController

//---synthesize the property---
@synthesize txtName;

//---displays an alert view when the button is clicked---
-(IBAction) btnClicked:(id) sender {
	NSString *str = [[NSString alloc]
					 initWithFormat:@"Hello, %@", txtName.text];
	UIAlertView *alert = [[UIAlertView alloc]
						  initWithTitle:@"Hello!"
						  message:str delegate:self
						  cancelButtonTitle:@"Done"
						  otherButtonTitles:nil];
	[alert show];
	[str release];
	[alert release];
}

/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/


// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
	//---release the outlet---
	[txtName release];
    [super dealloc];
}

@end
 
Wirelessly posted (Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5)

Hi - judging from what you posted, you need to put code in your app delegate to display the OutletsAndActionsViewController.

Did you make sure you followed the tutorial completely and accurately?
 
AppDelegate code

Here is what my AppDelegate files look like

Code:
//
//  OutletsAndActionsAppDelegate.h
//  OutletsAndActions


#import <UIKit/UIKit.h>

@class OutletsAndActionsViewController;

@interface OutletsAndActionsAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    OutletsAndActionsViewController *viewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet OutletsAndActionsViewController *viewController;

@end

Code:
//
//  OutletsAndActionsAppDelegate.m
//  OutletsAndActions


#import "OutletsAndActionsAppDelegate.h"
#import "OutletsAndActionsViewController.h"

@implementation OutletsAndActionsAppDelegate

@synthesize window;
@synthesize viewController;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
    // Override point for customization after app launch. 
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

	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)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.
     See also applicationDidEnterBackground:.
     */
}


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
}


- (void)dealloc {
    [viewController release];
    [window release];
    [super dealloc];
}


@end
 
Started over and worked fine.

I'm not sure what part of the code was different, but I started a new project and that worked fine. I check all the code that I added and it is the same so some other part must of inadvertently been changed. Thanks for the response.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.