PDA

View Full Version : simulator view different than interface builder view




kaz67
Jan 18, 2011, 04:54 PM
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.

//

#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


#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



OpRisk
Jan 18, 2011, 05:28 PM
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?

kaz67
Jan 19, 2011, 03:32 PM
Here is what my AppDelegate files look like

//
// 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

//
// 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

dejo
Jan 19, 2011, 04:05 PM
I am following a tutorial...
Which tutorial? It helps if you can be as specific as possible.

kaz67
Jan 20, 2011, 01:27 PM
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.