Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning iOS 4 Application Development
Password Reminder
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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:

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

Well what's the very first statement all about?
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?
Reply With Quote
  #2 (permalink)  
Old June 1st, 2011, 09:13 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

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.

Reply With Quote
  #3 (permalink)  
Old June 1st, 2011, 04:32 PM
Registered User
Join Date: May 2011
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts

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
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 01:45 AM.

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