Wrox Programmer Forums
|
BOOK: Beginning iPad Application Development
This is the forum to discuss the Wrox book Beginning iPad Application Development by Wei-Meng Lee; ISBN: 9780470641651
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning iPad 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 February 12th, 2011, 12:45 PM
Registered User
 
Join Date: Feb 2011
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 3 page 56, UIActionSheet

Hi,
I'm having trouble running the "UsingViews" example using the UIActionSheet. The UIAlertView example runs fine. Here's what I have:


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
/*
UIAlertView statements removed...
*/
UIActionSheet *action = [[UIActionSheet alloc]
initWithTitle:@"My action sheet"
delegate:self
cancelButtonTitle:@"OK"
destructiveButtonTitle:@"Delete message"
otherButtonTitles:@"Option 1", @"Option 2", nil];
[action showInView:self.view];
[action release];
/* I get the error with the statement below both active and commented-out
/* [super viewDidLoad]; */
}

I get an "EXEC_BAD_ACCESS" in the debugger. What's interesting is that when I am entering the [[UIActionSheet alloc] initWithTitle... definition, autofill does not want to complete the "destructiveButtonTitle" selector and I need to fill it out myself, as if it doesn't know anything about this selector. It's documented in the Developer Documentation. This seems to be a relevant portion of the crash dump:

19 UIKit 0x00638b89 -[UIActionSheet(Private) _addButtonWithTitle:label:buttonClass:] + 400
20 UIKit 0x0063497b -[UIActionSheet addButtonWithTitle:] + 57
21 UIKit 0x0063cf5c -[UIActionSheet initWithTitle:delegate:cancelButtonTitle:destructi veButtonTitle:otherButtonTitles:] + 131
22 UsingViews 0x00002304 -[UsingViewsViewController viewDidLoad] + 148 (UsingViewsViewController.m:48)
23 UIKit 0x0035e65e -[UIViewController view] + 179
24 UsingViews 0x00002321 -[UsingViewsViewController viewDidLoad] + 177 (UsingViewsViewController.m:49)
25 UIKit 0x0035e65e -[UIViewController view] + 179
26 UsingViews 0x00002321 -[UsingViewsViewController viewDidLoad] + 177 (UsingViewsViewController.m:49)
 
Old February 12th, 2011, 03:48 PM
Registered User
 
Join Date: Feb 2011
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default additional info

I was not looking so much for help in debugging, but rather to see if anyone else came across this problem. Also, for some reason there is a space in the debug output that does not exist in the actual code:

21 UIKit 0x0063cf5c -[UIActionSheet initWithTitle:delegate:cancelButtonTitle:destructi veButtonTitle:otherButtonTitles:] + 131

I'll revisit and see if there are any hidden characters. Any replies are much appreciated. Thanks!
 
Old February 12th, 2011, 07:53 PM
Friend of Wrox
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

You can't call the ActionSheet in the -viewDidLoad method since the view has not yet been assigned to a window.

Try this short experiment. Add the following to
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    NSLog(@"in application did finish launching");
    
    // Override point for customization after app launch. 
    [self.window addSubview:viewController.view];
    [self.window makeKeyAndVisible];
    NSLog(@"in application did finish launching");
	return YES;
}

Code:
- (void)viewDidLoad {
	NSLog(@"in view did load");		
    [super viewDidLoad];
}
and note the flow.

Since viewController has not yet been assigned to a window you can't tell the action sheet to display itself. There is no window yet, for it to do so. You can either create an action method in your viewController activated by a button in the interface for example, or do the following:
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    NSLog(@"in application did finish launching");
    
    // Override point for customization after app launch. 
    [self.window addSubview:viewController.view];
    [self.window makeKeyAndVisible];
	 NSLog(@"in application did finish launching");
	
	UIActionSheet *action = [[UIActionSheet alloc]
			                            initWithTitle:@"Title of ActionSheet"
							 delegate:viewController
					      cancelButtonTitle:@"OK"
					destructiveButtonTitle:@"Delete Message"
					       otherButtonTitles:@"Option 1", @"Option 2",nil];
	[action showInView:viewController.view];
	[action release];
	return YES;
}
To test out the code snippet.

Also make sure that the viewController conforms to the <UIActionSheetDelegate>

If you include this in your header the initWithTitle… method should autocomplete

Bob
The Following User Says Thank You to thepianoguy For This Useful Post:
[email protected] (February 12th, 2011)
 
Old February 12th, 2011, 10:34 PM
Registered User
 
Join Date: Feb 2011
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks a bunch!
I did notice in the debugger that it was calling the statements in viewDidLoad method in some sort of tight loop, and it took several seconds for the app to crash-- probably was an OOM or perhaps some sort of recursion limit was reached.

PRM





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chap 2 forums, pagination issues page 55-56 kenj BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 0 October 19th, 2009 09:28 PM
chapter 2 - page 41 problem creating the page.. jorjiana BOOK: Beginning Oracle Application Express ISBN: 9780470388372 2 August 22nd, 2009 04:25 AM
Access 2003 VBA PG 55-56 KellyR Access VBA 3 June 9th, 2007 08:32 AM
help an oldman (56) daviddisman C++ Programming 0 February 16th, 2007 11:53 AM
ZVON Tutorial Page 56 id() function scubaduba XSLT 1 November 1st, 2004 12:37 PM





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