iOs simple hello, name not working
I have recently started to learn Obj-C and Iphone development basically through Lynda.com iOs SDK essentials course. But it was written for Xcode 3.x and I have 4.0.x installed, so things are different. Basically, I take example from there and it just doesn't work for me and I can't f开发者_开发百科igure it out being a noob to it.
//basicViewController.h
#import <UIKit/UIKit.h>
@interface basicViewController : UIViewController {
IBOutlet UITextField *txtName;
IBOutlet UILabel *lblMessage;
}
@property (nonatomic, retain) IBOutlet UITextField *txtName;
@property (nonatomic, retain) IBOutlet UILabel *lblMessage;
- (IBAction) doSomething;
@end
And my basicViewController.m
#import "basicViewController.h"
@implementation basicViewController
@synthesize txtName;
@synthesize lblMessage;
- (IBAction) doSomething
{
NSString *msg = [[NSString alloc] initWithFormat:@"Hello, %@",txtName.text];
[lblMessage setText:msg];
[msg release];
}
- (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 {
[super dealloc];
}
@end
I haven't changed basicAppDelegate.h and .m from what they were created like. I think I will post them anyway.
//
// basicAppDelegate.h
#import <UIKit/UIKit.h>
@class basicViewController;
@interface basicAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
basicViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet basicViewController *viewController;
@end
//
// basicAppDelegate.m
#import "basicAppDelegate.h"
#import "basicViewController.h"
@implementation basicAppDelegate
@synthesize window;
@synthesize viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end
And here's my main.m:
//
// main.m
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
Also, on the Interface Builder window I have linked through File's Owner: label to lblMessage, TextField to txtName and doSomething to Button.
Now, the problem is: actually, the thing kinda works, only if I use the popup keyboard, not my physical one. And only if I type less than 3-4-5 symbols(differs sometimes). If I use my keyboard, not the popping one - it gives me Thread 1 received signal EXC_BAD_ACCESS. Same if I type too many symbols.
And I don't see much in All Output - just some usual stuff, the only suspicious line is:
warning:unable to compile regular expression "dyld"
Current language: auto; currently objective-c
(gdb)
So, guys, any kind help is appreciated.
First, there didn't change something since Xcode 3 except the interface.
Try to set a breakpoint and look where you app is crashing...
Try to delete the IBOutlets and create it new...
Try to create a new app...
If all not works, take your Mac and throw it outside a window, bring it back to Apple. (or install Xcode again --> much cheaper..)
I had the exact same problem and spent AGES looking for the solution. I found out how to make it work and I've made a tutorial on how to make the Hello, Name application on XCode. Take a look and see if it helps. I think if you follow the steps one by one you should have your app running in no time.
http://techtalktone.wordpress.com/2011/11/26/hello-world/
Hope this helps ;)
精彩评论