Undeclared Error and iPhone Simulator Crashing - iphone

Here's my code:
delegate.h
#import <UIKit/UIKit.h>
#class _4_Control_FunViewController;
#interface _4_Control_FunAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
_4_Control_FunViewController *viewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet _4_Control_FunViewController *viewController;
#end
delegate.m:
#import "_4_Control_FunAppDelegate.h"
#import "_4_Control_FunViewController.h"
#implementation _4_Control_FunAppDelegate
#synthesize window;
#synthesize viewController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions {
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
}
- (void)applicationWillTerminate:(UIApplication *)application {
}
#pragma mark -
#pragma mark Memory management
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
}
- (void)dealloc {
[viewController release];
[window release];
[nameField release];
[numberField release];
[super dealloc];
}
#end
ViewController.h
#import <UIKit/UIKit.h>
#interface _4_Control_FunViewController : UIViewController {
UITextField *nameField;
UITextField *numberField;
}
#property (nonatomic, retain) IBOutlet UITextField *nameField;
#property (nonatomic, retain) IBOutlet UITextField *numberField;
#end
ViewController.m
#import "_4_Control_FunViewController.h"
#implementation _4_Control_FunViewController
#synthesize nameField;
#synthesize numberField;
- (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
This is what I'm trying to get:
This is what I'm getting:

Looks like it "should" work, but based on your screenshot, I'd say you haven't got things connected correctly in Interface Builder.
Go to Interface Builder and make sure they are hooked up. Where ever you have an IBOutlet declared in a header file, that needs to be hooked up to the corresponding UI object in Interface Builder.
You also have some redundant code (shown below). They are not causing problems, but they double up because you have them declared as properties at the bottom your .h file. You can delete the lines below from your headers, but make sure you leave their corresponding #property declarations in place.
UIWindow *window;
_4_Control_FunViewController *viewController;
UITextField *nameField;
UITextField *numberField;

Related

Iphone keyboard and scroll wheel not appearing

I am having trouble with a webview. This webview loads a webpage with some inputfields and some droplists. The problem is that the keyboard and the scroll wheel don't appear. I see a quick 'flash' and the cursor does go in the selected inputfield, but the keyboard doesn't appear.
I'm using xcode 4.3.3
My Appdelegate.h
#import <UIKit/UIKit.h>
#class ViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate> {
UIWindow *windowTB;
UIViewController *tabBarVC;
// UIWebView *homeWebView;
}
#property (strong, nonatomic) IBOutlet UIWindow *windowTB;
#property (strong, nonatomic) IBOutlet UIViewController *tabBarVC;
//#property (strong, nonatomic) IBOutlet UIWebView *homeWebView;
#end
Appdelegate.m (the relevant part)
#import "AppDelegate.h"
#import "tabBarVC.h"
#import "homeVC.h"
#implementation AppDelegate
#synthesize windowTB;
#synthesize tabBarVC;
//#synthesize homeWebView;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self.windowTB setRootViewController:tabBarVC];
[self.windowTB makeKeyAndVisible];
return YES;
}
The homeVC.h
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#interface homeVC : UIViewController <UIWebViewDelegate>{
IBOutlet UIWebView *homeWebView;
}
#property (nonatomic, retain) UIWebView *homeWebView;
#end
And last homeVC.m
#import "AppDelegate.h"
#import "homeVC.h"
#implementation homeVC
#synthesize homeWebView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
return self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidLoad
{
[super viewDidLoad];
[homeWebView loadRequest:[NSURLRequest requestWithURL: [NSURL URLWithString:#"http://rolfdeenen.nl/test.html"]]];
}
I have been searching for a about a day now, but it just doesn't make sence to me. Can anyone help me?
Thanx!
Maybe the problem is in your webpage, because the webview has a standard behavior and you can't modify it.

Trouble using a UIButton to transition UIViews

I am a very inexperienced developer and have run into a problem that should be easy however after hours of reading over Apple's Developer guide and many different questions on this site I am still stumped.
All I am trying to do is transition from my root view controller to my next view controller via a UIButton.
Here is appdelegate.h:
#import <UIKit/UIKit.h>
#class MainViewController;
#interface MDAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
#end
Important stuff from Appdelegate.m:
#import "MDAppDelegate.h"
#import "MainViewController.h"
#implementation MDAppDelegate
#synthesize window, navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions (NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
MainViewController.h:
#import <UIKit/UIKit.h>
#interface MainViewController : UIViewController {
UIButton *cityButton;
}
#property (nonatomic, retain) IBOutlet UIButton *cityButton;
- (IBAction)chooseCityAction:(id)sender;
#end
And finally, MainViewController.m:
#import "MainViewController.h"
#import "DailyDealViewController.h"
#implementation MainViewController
#synthesize cityButton;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)dealloc
{
[cityButton release];
[super dealloc];
}
- (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.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
temporaryBarButtonItem.title = #"Back";
self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
[temporaryBarButtonItem release];
}
- (void)viewDidUnload
{
[self setCityButton:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)chooseCityAction:(id)sender {
DailyDealViewController *dailyDealViewController = [[DailyDealViewController alloc]initWithNibName:#"DailyDealViewController" bundle:nil];
[dailyDealViewController release];
[self.navigationController pushViewController:dailyDealViewController animated:YES];
}
#end
Here is the error:
2011-10-03 21:56:14.258 MD[4235:207] *** Terminating app due to uncaught exception
'NSUnknownKeyException', reason: '[<UIViewController 0x4b434c0>
setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key
cityButton.'
I would love to know what I missing.
You have released dailyDealViewController before pushing it. Move the release statement to after the pushViewController statement.

Loading a new view before the old one iphone sdk

Probably just a simple question, but ive been building a little puzzle game and no decided i could do with a menu for it. Ive created the menu no problem i just cant get it to show before the puzzle. Ive tried changing the code in the appdelegate but its not liking it.
slider appdelegate.h
#import <UIKit/UIKit.h>
#class SliderViewController;
#class MainMenu;
#interface SliderAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
MainMenu *viewController1;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet SliderViewController *viewController;
#property (nonatomic, retain) IBOutlet MainMenu *viewController1;
#end
Slider appdelegate.m
#import "SliderAppDelegate.h"
#import "SliderViewController.h"
#implementation SliderAppDelegate
#synthesize window;
#synthesize viewController;
#synthesize viewController1;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[self.window addSubview:viewController1.view];
[self.window makeKeyAndVisible];
return YES;
}
But doing that throws out an error:
error: request for member 'view' in
something not a structure or union
I know its probably a stupid question but could anyone help please.
You need to import that class and make alloc the object first see this
Slider appdelegate.m
#import "SliderAppDelegate.h"
#import "SliderViewController.h"
#import "MainMenu.h"//change here
#implementation SliderAppDelegate
#synthesize window;
#synthesize viewController;
#synthesize viewController1;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
viewController = [[[MainMenu alloc] initWithNibName#"MainMenu" bundle:nil] autorelease]; // and here
[self.window addSubview:viewController1.view];
[self.window makeKeyAndVisible];
return YES;
}

Iphone SDK 4.0 -->> simulator just sits there and doesn't load the ap

I have started learning iphone apps development. However when I build and run the project, the simulator opens with new app icon. When I click on the new app icon ...nothing happens.
-->> simulator just sits there and doesn't load the app
Any help will be appreciated.
Marty
Actually it is not my code. I got it from the book I am studying from. Here it is:-
#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
//------------------------
#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

change a label from another view

I have a label on my main View. I have a button which brings me to another view. On it I have a button to change my label which is on the main view.
How can I do this? I included a projet, could someone help me please...
I usually use a delegate protocol:
in the second view h add :
#protocol viewControllerDelegate;
#interface viewController : UIView
id < viewControllerDelegate > delegate;
#property (nonatomic, assign) id < QuickViewControllerDelegate > delegate;
#end
#protocol viewControllerDelegate
- (void)viewController:(ViewController *)controller stringForLabel:(NSString*)string;
#end
in the second view m file call:
[delegate quickViewController:self
stringForLabel:#"your string"];
in the main view h file add: , like that:
#interface MainView:UIViewController<viewControllerDelegate>
in the main view m file:
first: when you init the second view don't forget to add:
secondview.delegate = self;
other wise it wont work.
second: add the delegate function:
- (void)viewController:(ViewController*)controller stringForLabel:(NSString*)string{
//set the label from the string passed
lable.text = string;
}
hope it will help
shani
O.K i usually don't do that but for now...
this are your files after i have change them -
View1 .h (try to name those files with a capital letter);
#import <UIKit/UIKit.h>
#protocol View1Delegate;
#interface View1 : UIViewController {
id <View1Delegate> delegate;
IBOutlet UIButton *btn_changelbl;
IBOutlet UIButton *btn_back;
}
#property (nonatomic, assign) id <View1Delegate> delegate;
#property (nonatomic,retain) IBOutlet UIButton *btn_changelbl;
#property (nonatomic,retain) IBOutlet UIButton *btn_back;
-(IBAction) backToMain:(id)sender;
-(IBAction) changeLabel:(id)sender;
#end
#protocol View1Delegate
- (void)view1:(View1*)controller labelNeedsChage:(BOOL)needsChange stringForLabel:(NSString*)string;
#end
View1.m
#import "View1.h"
#import "testViewController.h"
#implementation View1
#synthesize delegate;
#synthesize btn_changelbl;
#synthesize btn_back;
-(IBAction) backToMain:(id)sender {
[self dismissModalViewControllerAnimated:YES];
[delegate view1:self labelNeedsChage:NO stringForLabel:nil];
}
-(IBAction) changeLabel:(id)sender{
[delegate view1:self labelNeedsChage:YES stringForLabel:#"new text"];
[self dismissModalViewControllerAnimated: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 {
[super viewDidUnload];
}
- (void)dealloc {
[btn_changelbl release];
[btn_back release];
[super dealloc];
}
#end
TestViewController.h
#import <UIKit/UIKit.h>
#import "View1.h"
#interface testViewController : UIViewController<View1Delegate> {
IBOutlet UILabel *lb_test;
IBOutlet UIButton *btn_changeView;
}
#property (nonatomic,retain) IBOutlet UILabel *lb_test;
#property (nonatomic,retain) IBOutlet UIButton *btn_changeView;
-(IBAction) changeView:(id)sender;
#end
TestViewController.m
#import "testViewController.h"
#import "view1.h"
#implementation testViewController
#synthesize lb_test;
#synthesize btn_changeView;
-(IBAction) changeView:(id)sender {
View1 *myView = [[View1 alloc] init];
myView.delegate=self;
[self presentModalViewController:myView animated:YES];
}
- (void)view1:(View1*)controller labelNeedsChage:(BOOL)needsChange stringForLabel:(NSString*)string{
if(needsChange){
lb_test.text=string;
}
}
- (void)dealloc {
[lb_test release];
[btn_changeView release];
[super dealloc];
}
#end
Thats it.
by the way:
you had many small mistakes that i have fixed. look at the fixes to try to understand them.