 |
BOOK: Beginning iOS 4 Application Development
 | This is the forum to discuss the Wrox book Beginning iOS 4 Application Development by Wei-Meng Lee; ISBN: 978-0-470-91802-9 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning iOS 4 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

January 28th, 2011, 11:06 PM
|
Registered User
|
|
Join Date: Jan 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
more Chapter 3 Fun Time
I got the first example working once, but for whatever reason, when I try to do it again it doesn't work. Can you tell me where I'm going wrong? The button just isn't popping up.
Working version:
Quote:
H file
//
// outlets_and_actionsViewController.h
// outlets and actions
//
// Created by Tam Hartman on 1/27/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface outlets_and_actionsViewController : 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
|
Quote:
M FILE
#import "outlets_and_actionsViewController.h"
@implementation outlets_and_actionsViewController
//-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:@"Are you a Cylon?"
message:str
delegate:self
cancelButtonTitle:@"I'm A Frakin Cylon!"
otherButtonTitles:nil];
[alert show];
[str release];
[alert release];
}
-(void)dealloc{
//release the outlet
[txtName release];
[super dealloc];
}
|
and here's what isn't working:
Quote:
M file
#import "outlets_and_actions_2ViewController.h"
@implementation outlets_and_actions_2ViewController
//-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];
}
-(void)dealloc{
//release the outlet
[txtName release];
[super dealloc];
}
|
Quote:
h file
//
// outlets_and_actions_2ViewController.h
// outlets and actions 2
//
// Created by Tam Hartman on 1/28/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface outlets_and_actions_2ViewController : 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
|
maybe someone will see something that I'm not?
|

January 28th, 2011, 11:33 PM
|
Friend of Wrox
|
|
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
|
|
Check that you connected and SAVED your outlets and actions in Interface Builder. The code is fine.
Bob
|

January 28th, 2011, 11:35 PM
|
Registered User
|
|
Join Date: Jan 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by thepianoguy
Check that you connected and SAVED your outlets and actions in Interface Builder. The code is fine.
Bob
|
done and done. still not working.
|

January 28th, 2011, 11:39 PM
|
Friend of Wrox
|
|
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
|
|
The code looked fine, I set up the project and did a copy and paste of your code into the .h and .m files and it worked as expected
If you want send your non-working project files to
ipadhelper@me.com
and I'll take a quick look at it for you.
|

January 28th, 2011, 11:42 PM
|
Registered User
|
|
Join Date: Jan 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by thepianoguy
The code looked fine, I set up the project and did a copy and paste of your code into the .h and .m files and it worked as expected
If you want send your non-working project files to
ipadhelper@me.com
and I'll take a quick look at it for you.
|
sent. Thank you :)
|

January 29th, 2011, 08:33 AM
|
Friend of Wrox
|
|
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
|
|
Happy to help.
|

February 6th, 2011, 12:08 AM
|
Registered User
|
|
Join Date: Feb 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chapter 3 , im getting the following two errors underlinded
//
// OutletsAndActionsViewController.m
// OutletsAndActions
//
// Created by Dean on 2/5/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#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];
message:str
delegate:self (error saids "expected before delegate"
cancelButtonTitle:@"Done"
[otherButtonTitles:nil];
[alert show];(error here saids "alert undeclared first use in this action")
[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 {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// 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:(UIIn terfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (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
|

February 6th, 2011, 08:22 AM
|
Friend of Wrox
|
|
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
|
|
Based on the code you have provided, you are missing a line. No UIAlertView is defined or allocated, and part of the initialization is missing.
The missing line is in bold
Code:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello!"
message:str
delegate:self
cancelButtonTitle:@"Done"
otherButtonTitles:nil];
|

February 6th, 2011, 12:36 PM
|
Registered User
|
|
Join Date: Feb 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ahhh, thanks piano guy. it launched ok now. 
|
|
 |
|