p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning iPhone SDK Programming with Objective-C (http://p2p.wrox.com/forumdisplay.php?f=543)
-   -   Page 66-67, app crash (http://p2p.wrox.com/showthread.php?t=78287)

chillbumps February 21st, 2010 10:51 AM

Page 66-67, app crash
 
When I run the secret PIN version of the BasicUI app, it will not accept PIN entry. When I click on the pin buttons, the app crashes. My code builds and runs with no errors or warnings.
I also believe there's an error on page 66. Some of the code that needs to be entered is not in bold.
This book is already a bit outdated as the SDK no longer allows you to create outlets and actions in the way the book describes. I finally found the errata page. Its not the simplest to find as somehow I ended up on the ebook version first.

All this makes it difficult to flow through this book.

[B)]

londo-cat February 21st, 2010 07:00 PM

Quote:

Originally Posted by chillbumps (Post 253883)
When I run the secret PIN version of the BasicUI app, it will not accept PIN entry. When I click on the pin buttons, the app crashes. My code builds and runs with no errors or warnings.
I also believe there's an error on page 66. Some of the code that needs to be entered is not in bold.
This book is already a bit outdated as the SDK no longer allows you to create outlets and actions in the way the book describes. I finally found the errata page. Its not the simplest to find as somehow I ended up on the ebook version first.

All this makes it difficult to flow through this book.

[B)]

There was a PDF update by Wei-Meng about that issue with the outlets and actions. But even so, I found that the first example in chapter two (Hello World) didn't even work properly.

Sp666ky July 29th, 2010 04:32 AM

Hi there,
I am going through this book too and it can be quite frustrating. I am struggling with the errata but seem to muddle around it. But learning a language with no mentor is usually frustrating.

On the subject of the buttons not acting.
I take ORIGINAL the code from btnClicked function and insert it in other sections to see if the code has got that far. Try it.

With the buttons not working and maybe the program stopping I found I had a spelling error. I had written "button" instead of "btn" in some examples. Check all your files and check what your buttons are calling.

I am only this far in the book and am far from being an expert but, I hope that is of help.

Sp666ky July 29th, 2010 04:42 AM

My problem
 
I too have a problem in this section of the book.

In the BtnClicked function in its new "if" statment.
I get the warning - NSMutableString' may not respond to '-isEqualToString' [:confused:]

diogermani December 22nd, 2010 03:27 PM

Chapter 3 source code error
 
I´ve downloaded the source code for this example and it didnt worked for several reasons, the way I had it working was:

first I´ve changed the Base SDK in the "Project -> Edit Project Settings", "build" tab, "Base SDK" to Latest.

then I was able to publish it, but nothing was happening when I was clicking in the "Click me" button, the thing here is that the button in the interface builder was not linked to the File´s owner action btnClicked:

To solve that just double click in the BasicUIView.xib ;
click in the "click me" button to highlight it;
right click in the "click me" button and drag it to "File´s owner" icon,
when you release the button select "btnClicked:" event.

I hope I helped someone.

Best regards.

Dio

Mons June 24th, 2011 02:14 AM

Quote:

Originally Posted by chillbumps (Post 253883)
When I run the secret PIN version of the BasicUI app, it will not accept PIN entry. When I click on the pin buttons, the app crashes. My code builds and runs with no errors or warnings.
I also believe there's an error on page 66. Some of the code that needs to be entered is not in bold.
This book is already a bit outdated as the SDK no longer allows you to create outlets and actions in the way the book describes. I finally found the errata page. Its not the simplest to find as somehow I ended up on the ebook version first.

All this makes it difficult to flow through this book.

[B)]

Hi Chillbumps, I just saw your post after posting my concerns about the same subject If you managed to sort out the interface let me know

thepianoguy June 24th, 2011 08:19 AM

If you post your viewController code someone should be able to sort out your problem. If the problem is not in the code, but rather in the IB connections, it will be necessary to actually see the project. You could send it to
ipadhelper@me.com
It would only take a minute or two to sort out.
The first thing I would do is compare your code to the download and check for discrepancies. There is an error in the download that needs to be fixed for it to run properly. The action method has not been connected to the Click Me button. This needs to be done for the alertView to actually show up.

Bob

Mons June 25th, 2011 01:42 AM

Crashing Chapter 3 BasicUI
 
Hi Bob thanks for the quick reply and offer of support. I did swap the code which I hand set after struggling with a few typos. I switched it for the downloaded version of the basicUI m file in case I had missed something: Also Simulator 3.1.1. is what I am running. The app succeeds It is the linkage I think is the problem. Any further advice welcome. thanks for the interest.

[code]
#import "BasicUIViewController.h"

@implementation BasicUIViewController
@synthesize nameTextField;

- (IBAction)clearPinBtnClicked:(id)sender {
[secretPin setString:@""];
}

- (IBAction)pinBtnClicked:(id)sender {
[secretPin appendString:[sender titleForState:UIControlStateNormal]];
}

- (IBAction)btnClicked:(id)sender {
if ([secretPin isEqualToString: @"2345"]) {
NSString *str = [[NSString alloc] initWithFormat:@"Hello, %@", nameTextField.text ];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Hello"
message: str
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
[alert release];
[str 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 {
secretPin = [[NSMutableString alloc] initWithCapacity:2];
[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 {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}


- (void)dealloc {
[nameTextField release];
[secretPin release];
[super dealloc];
}

@end[/QUOTE]

thepianoguy June 25th, 2011 08:15 AM

There is nothing wrong with the code you provided. You mentioned using Simulator 3.1.1, which version of Xcode are you using? One of the common user errors in the 3.x.x versions of Xcode is failure to save changes made in Interface Builder, particularly after connecting Outlets or Actions. This is also a common omission in the book, as it is sometimes included as a step, and sometimes not, so verify your connections. The alertView will only show up if the correct PIN number is entered, the nameTextField can be blank. To check secretPin value and to check the connection in the btnClicked:(id)sender method insert the following
Code:

- (IBAction)btnClicked:(id)sender {
        NSLog(@"In buttonClicked. The secretPin is %@", secretPin);
        if ([secretPin isEqualToString: @"2345"]) {
            NSString *str = [[NSString alloc] initWithFormat:@"Hello, %@", nameTextField.text ];
            UIAlertView *alert = [[UIAlertView alloc]
                                                initWithTitle:@"Hello" 
                                                message: str 
                                                delegate:self 
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
            [str release];
        }
}

Run the project and see what the console log displays.

If you still have problems, send the project to the email in my last post, and I will track down the issue and set you on the right path.

Bob


All times are GMT -4. The time now is 12:11 PM.

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