Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning iPad Application Development
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 12th, 2011, 11:45 AM
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)
Reply With Quote
  #2 (permalink)  
Old February 12th, 2011, 02: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!
Reply With Quote
  #3 (permalink)  
Old February 12th, 2011, 06:53 PM
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: 297
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
Reply With Quote
The Following User Says Thank You to thepianoguy For This Useful Post:
marqrdt@gmail.com (February 12th, 2011)
  #4 (permalink)  
Old February 12th, 2011, 09: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
Reply With Quote
Reply


Thread Tools
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
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 10:53 AM
ZVON Tutorial Page 56 id() function scubaduba XSLT 1 November 1st, 2004 11:37 AM



All times are GMT -4. The time now is 02:55 AM.


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