Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old November 9th, 2010, 11:45 AM
Registered User
 
Join Date: Nov 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 3

I am having trouble displaying a message in Chapter 3.

Here is the code I submitted and the errors I am getting are

No initwithformat message found??


//
// OutletsandActionsViewController.m
// OutletsandActions
//
// Created by LanceD on 11/9/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "OutletsandActionsViewController.h"

@implementation OutletsandActionsViewController

//synth
@synthesize txtName;

//alert
-(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:(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
[txtName release];
[super dealloc];
}

@end
  #2 (permalink)  
Old November 10th, 2010, 12:01 AM
Authorized User
Points: 172, Level: 3
Points: 172, Level: 3 Points: 172, Level: 3 Points: 172, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2010
Posts: 21
Thanks: 0
Thanked 6 Times in 4 Posts
Default Check your caps ;-)

It should be initWithFormat. Note the "W".
  #3 (permalink)  
Old November 24th, 2010, 11:46 AM
Registered User
 
Join Date: Nov 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

I also have a problem with this Chapter 3 example.

Running the code belows returns the error:
No '-initWithTitle:message:delegate:cancelButtonTitle:o therButtonTitles:' method found. It then lists the path to ViewController.m
(Messages without a matching method signature will be assumed to return 'id')

The coding on .m

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
						  delgate:self
						  cancelButtonTitle:@"Done"
						  otherButtonTitles:nil];
                           //---- problem occurs here ^^ ----
	[alert show];
	[str release];
	[alert release];
}

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


/*
// 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 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 {
    [super dealloc];
}

@end
Thank you for your help !
  #4 (permalink)  
Old November 24th, 2010, 09:05 PM
Authorized User
Points: 172, Level: 3
Points: 172, Level: 3 Points: 172, Level: 3 Points: 172, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2010
Posts: 21
Thanks: 0
Thanked 6 Times in 4 Posts
Default Typo: delegate is spelled wrongly

Your code has spelled the delegate wrongly. ;-)
  #5 (permalink)  
Old November 25th, 2010, 07:40 PM
Registered User
 
Join Date: Nov 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Wei-Ming,

Thank you for your quick reply. I am happy to report the code works as intended =)
However, I have two more questions.
I have another problem on the same chapter. I am trying to use pageControl and imageView1/imageview2 and while the code compiles without any errors, the images do not come up. The images were downloaded from this website and drag/dropped into the Resources folder.

The last question I have is regarding your help on the forum. Is there a limit to your patience in helping your readers (i.e. me) as they go through your book? Contacting you or appealing to the forums should obviously not be the first response to a debug error but if all else fails.. I know for sure you would be able to tell me what's wrong.

Thanks =)

Code:
#import "UsingViewsViewController.h"

@implementation UsingViewsViewController

@synthesize pageControl;
@synthesize imageView1, imageView2;

/* /--actionSheet code. Chapter 3
- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex {
	NSLog (@"%d", buttonIndex);
}

 */
/*
// 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 {
}
*/

- (void)viewDidLoad {
	//--initialize the first imageview to display an image--
	[imageView1 setImage:[UIImage imageNamed:@"iMac_old.jpeg"]];
	tempImageView = imageView2;
	
	//--make the first imageview visible and hide the second--
	[imageView1 setHidden:NO];
	[imageView2 setHidden:YES];
	
	//--add the event handler for the page control--
	[pageControl addTarget:self
					action:@selector(pageTurning:)
		  forControlEvents:UIControlEventValueChanged];

[super viewDidLoad];
}

//--when the page control's value is changed--
- (void) pageTurning: (UIPageControl *) pageController {
	//--get the page number you can turning to--
	NSInteger nextPage = [pageController currentPage];
	switch (nextPage) {
		case 0:
			[tempImageView setImage:
			 [UIImage imageNamed:@"iMac_old.jpeg"]];
			break;
		case 1:
			[tempImageView setImage:
			 [UIImage imageNamed:@"iMac.jpeg"]];
		case 2:
			[tempImageView setImage:
			 [UIImage imageNamed:@"Mac8100.jpeg"]];
		case 3:
			[tempImageView setImage:
			 [UIImage imageNamed:@"MacPlus.jpeg"]];
		case 4:
			[tempImageView setImage:
			 [UIImage imageNamed:@"MacSE.jpeg"]];
			break;
		default:
			break;

	}

//--switch the two imageview views--
	if (tempImageView.tag == 0) { //--imageView1--
		tempImageView = imageView2;
		bgImageView = imageView1;
	}
	else {		//--imageView2--
		tempImageView = imageView1;
		bgImageView = imageView2;
	}
	
//--animate the two views flipping--
	[UIView beginAnimations:@"flipping view" context:nil];
	[UIView setAnimationDuration:0.5];
	[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
	[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
						   forView:tempImageView
							 cache:YES];
	[tempImageView setHidden:YES];
	[UIView commitAnimations];
	[UIView beginAnimations:@"flipping view" context:nil];
	[UIView setAnimationDuration:0.5];
	[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
	[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
						   forView:bgImageView
							 cache:YES];
	[bgImageView setHidden:NO];
	[UIView commitAnimations];
}

- (void)dealloc {
	[pageControl release];
	[imageView1 release];
	[imageView2 release];
	[super dealloc];
}

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	UIActionSheet *action = [[UIActionSheet alloc]
							 initWithTitle:@"Title of Action Sheet"
							 delegate:self
							 cancelButtonTitle:@"OK"
							 destructiveButtonTitle:@"Delete Message"
							 otherButtonTitles:@"Option 1", @"Option 2", nil];
	[action showInView:self.view];
	[action release];
 [super viewDidLoad];
}
*/


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)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;
}


@end
  #6 (permalink)  
Old January 9th, 2011, 11:11 PM
Registered User
 
Join Date: Jan 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default Here is how I overcame the issue that you are facing:

In the pageTurning method, the setImage instructions are storing the next jpeg image into the tempImageView class. However, the switch imageview views section is then overlaying the contents of tempImageView with that of imageView2, which was initialized previously (probably with null) at the beginning of the viewDidLoad method and the initial image stored in imageView1 is then stored into bgImageView.

It is the same image that is currently being diaplayed! Therefore it doesn't appear to change images at all.

My solution was to change all the instances of tempImageView in the pageTurning method to 'imageView1'. Therefore in the switch section, the next jpeg is allowed to be stored in the bgImageView and then the animation routine has something different to display.
  #7 (permalink)  
Old January 17th, 2011, 02:20 PM
Registered User
 
Join Date: Jan 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by ghestrada View Post
In the pageTurning method, the setImage instructions are storing the next jpeg image into the tempImageView class. However, the switch imageview views section is then overlaying the contents of tempImageView with that of imageView2, which was initialized previously (probably with null) at the beginning of the viewDidLoad method and the initial image stored in imageView1 is then stored into bgImageView.

It is the same image that is currently being diaplayed! Therefore it doesn't appear to change images at all.

My solution was to change all the instances of tempImageView in the pageTurning method to 'imageView1'. Therefore in the switch section, the next jpeg is allowed to be stored in the bgImageView and then the animation routine has something different to display.
I have made the same changes that you supplied but have not had any success. I just get the old iMac image. I am not able to see the 5 dots for the page controller item either. Also, the old iMac image appears to have stretched to cover the entire length of the screen, even though I left space at the bottom of the screen for the five dots.

I also looked through the source code and it appears to be the same as mine. I am unable to test the source code, as it complains about my not having iPhones 4.0 SDK. I am running 4.2. Would the small version difference be the cause of this not working properly for me?
  #8 (permalink)  
Old January 18th, 2011, 12:37 AM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

There are a couple of threads that touch on some common errors in this chapter
Chapter 3 Page Control & Image Views
is from a prior book by the author with the same project
and
Views Controller question

As far as testing the source code with the downloaded project. Open it in Xcode, then either double click or select and Command-I (Get Info) the top listing (blue icon) in the Groups & Files pane. In the Get Info panel that opens, find the Base SDK row (under Architectures), and click the Value column item (probably says iOS 4.0). Change the selection to:
latest iOS (Currently set to iOS 4.2)
After making the change, quit Xcode and then reopen the project. You should now be able to build and run.

If the threads above don't point you to a solution, I would suggest that you try the project one more time, and make sure that you have saved all changes in both Xcode and Interface Builder as you make them. The need to save changes in Interface Builder is omitted in the project steps in the book.
If you still can't work out the problem send your project files to
ipadhelper@me.com and I will sort it out and get back to you.
Bob
  #9 (permalink)  
Old January 18th, 2011, 09:43 AM
Registered User
 
Join Date: Jan 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Red face OK, I'm really embarassed now...

I reviewed every step of my entering the project. I placed the project in debug and stepped thru the execution of the program several times, observing the values of all of the objects.

What I found is that evaluation of the Tag value was following the same branch of the IF statement everytime, no matter if I went forward or backwards on the PageControl.

Looking deeper, I discovered that I had transposed the Tag values of the ImageViews in the Interface Builder.

I then set them correctly, backed out my changes in the Switch block, saved everything, and then retested.

IT WORKS!

What a nube!

Last edited by ghestrada; January 18th, 2011 at 10:32 AM..
  #10 (permalink)  
Old January 18th, 2011, 10:24 AM
Registered User
 
Join Date: Jan 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by thepianoguy View Post
As far as testing the source code with the downloaded project. Open it in Xcode, then either double click or select and Command-I (Get Info) the top listing (blue icon) in the Groups & Files pane. In the Get Info panel that opens, find the Base SDK row (under Architectures), and click the Value column item (probably says iOS 4.0). Change the selection to:
latest iOS (Currently set to iOS 4.2)
After making the change, quit Xcode and then reopen the project. You should now be able to build and run.
Thanks Bob, I will try your suggestions.

Quote:
Originally Posted by ghestrada View Post
I reviewed every step of my entering the project. I placed the project in debug and stepped thru the execution of the program several times, observing the values of all of the objects.

What I found is that evaluation of the Tag value was following the same branch of the IF statement everytime, no matter if I went forward or backwards on the PageControl.

Looking deeper, I discovered that I had transposed the Tag values of the ImageViews in the Interface Builder.

I then set them correctly, backed out my changes in the Case block, saved everything, and then retested.

IT WORKS!

What a nube!
It looks as though I'll have to redo that exercise since it helped you and I'm pretty sure I out-newb you.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 6 - Code Download Missing for this Chapter dbaechtel BOOK: Professional SharePoint 2007 Development ISBN: 978-0-470-11756-9 0 August 11th, 2009 11:02 AM
Chapter 2 - End of chapter exercises whizzkid1892 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 July 30th, 2008 12:02 PM
Generics chapter 12 difficult chapter i found ...? Larryz C# 2005 1 July 4th, 2007 09:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.