Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning iOS 4 Application Development
|
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
 
Old May 27th, 2011, 11:11 PM
Registered User
 
Join Date: May 2011
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ch. 6 - ScrollView - "if (keyboardIsShown) return;" ??

this is regarding the program that makes the view scroll up when the Keyboard appears, so that it (the Keyboard) doesn't cover-up and hide what's already on-screen: at the bottom of page 173 the code is:

Code:
// When the keyboard appears:
-(void) keyboardDidShow: (NSNotification *) notification {
	if (keyboardIsShown) return;
	
	NSDictionary *info = [notification userInfo];
	NSLog(@"Here's our Notification: %@" , notification);
etc.

Well what's the very first statement all about?
Code:
if (keyboardIsShown) return;
What is it returning? The method itself is of type (void) so its not relating to that.
Nor is it causing the method to exit at that point - so what is it doing? why do we need it?
 
Old June 1st, 2011, 09:13 AM
Friend of Wrox
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

Nothing is returning, it is simply a way to exit the method. The "if" statement could be structured to avoid it. However, in this example, keyboardIsShown is never going to be YES in this method, so it can be omitted.
The keyboardDidShow method is called when a textField is clicked on - keyboardIsShown is NO
If the view is rotated while the keyboard is visible, the keyboardDidHide method is called setting the keyboardIsShown back to NO and then immediately calling keyboardDidShow. In this example the if (keyboardIsShown) statement is not needed.

Also note in the project, that there is an error in the removeObserver code in the -viewWillDisappear method. The method names should match those in the addObserver registrations. This has been brought up in a previous thread.

Bob
 
Old June 1st, 2011, 04:32 PM
Registered User
 
Join Date: May 2011
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

starting at the end - yes, I did notice the errors in the removeObserver code (removing the "WillShowNotification" and "WillHideNotification" methods when what was actually added earlier were the "DidShow" and "DidHide" notifications - a glaring mismatch) - and it threw me for yet another frustrating loop till I figured it out.

(I must say, I'm becoming more and more "impressed" with how little care the Author or Publishers of this book seemed to have had when putting it out. SO MANY code errors... Or Apps that crash even though the code was typed in exactly as appears in the book...)

In terms of the "return" statement - understood :-)
I also looked it up in the Kochan Objective-C book (a wonderful, error-free book ) - and right there in Appendix B it goes through all the different type of "Statements" there are and for "The Return Statement" it states: "Execution of the return statement causes program execution to be immediately returned to the calling function or method."

So I was like "oh....duh!!!..."

Well, hopefully someone else down the line will benefit from this and all our other posts and "duhs"


I'm now on Chapter 15 and currently experiencing one of those inexplicable App-crashes - even though I typed the code in exactly as it appears in the book...

May be posting about that soon - stay tuned





Similar Threads
Thread Thread Starter Forum Replies Last Post
No return text on "First ASP.NET Web Page" dogfacemarc BOOK: Beginning ASP.NET 4 : in C# and VB 10 December 22nd, 2010 03:35 AM
MSXSL gives error message for "for" inside "select" ilyaz XSLT 1 December 9th, 2010 05:02 PM
Add a CheckBox DataColumn to my DataGridView, Null format: "" or "True" but Error: F ismailc C# 2005 0 September 25th, 2009 04:56 AM
Trouble with "Return to Sender" Javascript in CHPT 12 mmeth BOOK: Professional Microsoft Office SharePoint Designer 2007 ISBN: 978-0-470-28761-3 1 September 3rd, 2009 08:20 AM





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