-2

I try to make a PickerView with ActionSheet.The code is ok in X-code, but crash will occur when I run it and press the "Button", please help to check what have I missed?

Thank you.

Here is the .h file

#import <UIKit/UIKit.h>

@interface UIPickerView_ActionSheetViewController : UIViewController <UIActionSheetDelegate, UIPickerViewDelegate>
{
    IBOutlet UIButton *button;
}

@property (nonatomic, retain) UIButton *button;

- (IBAction)buttonPressed;

@end

Here is the .m file

#import "UIPickerView_ActionSheetViewController.h"

@implementation UIPickerView_ActionSheetViewController

@synthesize button;

- (IBAction)buttonPressed
{
    UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"currentData"
                                                  delegate:self 
                                         cancelButtonTitle:@"Done"
                                    destructiveButtonTitle:@"Cancel" 
                                         otherButtonTitles:nil];


    UIPickerView *pickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0,40,480,200)];

    pickerView.delegate = self; 
    pickerView.showsSelectionIndicator = YES;     

    [menu addSubview:pickerView]; 
    [menu showInView:self.view]; 
    [menu setBounds:CGRectMake(0,0,480, 320)];

    [pickerView release]; 
    [menu release];
}

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

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload
{
    self.button=nil;
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

Crash on int retVal = UIApplicationMain(argc, argv, nil, nil);

#import <UIKit/UIKit.h>

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

Crash Info

#0  0x9631817a in __kill ()
#1  0x9631816c in kill$UNIX2003 ()
#2  0x963aa879 in raise ()
#3  0x963c09b8 in abort ()
#4  0x9619dfda in __gnu_cxx::__verbose_terminate_handler ()
#5  0x00f1c23b in _objc_terminate ()
#6  0x9619c17a in __cxxabiv1::__terminate ()
#7  0x9619c1ba in std::terminate ()
#8  0x9619c2b8 in __cxa_throw ()
#9  0x00f1c416 in objc_exception_throw ()
#10 0x00dca0bb in -[NSObject(NSObject) doesNotRecognizeSelector:] ()
#11 0x00d39966 in ___forwarding___ ()
#12 0x00d39522 in __forwarding_prep_0___ ()
#13 0x0001a4fd in -[UIApplication sendAction:to:from:forEvent:] ()
#14 0x000aa799 in -[UIControl sendAction:to:forEvent:] ()
#15 0x000acc2b in -[UIControl(Internal) _sendActionsForEvents:withEvent:] ()
#16 0x000ab7d8 in -[UIControl touchesEnded:withEvent:] ()
#17 0x0003eded in -[UIWindow _sendTouchesForEvent:] ()
#18 0x0001fc37 in -[UIApplication sendEvent:] ()
#19 0x00024f2e in _UIApplicationHandleEvent ()
#20 0x01001992 in PurpleEventCallback ()
#21 0x00da9944 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#22 0x00d09cf7 in __CFRunLoopDoSource1 ()
#23 0x00d06f83 in __CFRunLoopRun ()
#24 0x00d06840 in CFRunLoopRunSpecific ()
#25 0x00d06761 in CFRunLoopRunInMode ()
#26 0x010001c4 in GSEventRunModal ()
#27 0x01000289 in GSEventRun ()
#28 0x00028c93 in UIApplicationMain ()
#29 0x00001c09 in main (argc=1, argv=0xbfffef8c) at main.m:14

Maybe this can help more

Attaching to process 606.
2011-12-10 06:37:08.456 UIPickerView_ActionSheet[606:207] -[UIPickerView_ActionSheetViewController DatePickerView]: unrecognized selector sent to instance 0x602dfb0
2011-12-10 06:37:08.458 UIPickerView_ActionSheet[606:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPickerView_ActionSheetViewController DatePickerView]: unrecognized selector sent to instance 0x602dfb0'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x00dc85a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x00f1c313 objc_exception_throw + 44
    2   CoreFoundation                      0x00dca0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x00d39966 ___forwarding___ + 966
    4   CoreFoundation                      0x00d39522 _CF_forwarding_prep_0 + 50
    5   UIKit                               0x0001a4fd -[UIApplication sendAction:to:from:forEvent:] + 119
    6   UIKit                               0x000aa799 -[UIControl sendAction:to:forEvent:] + 67
    7   UIKit                               0x000acc2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    8   UIKit                               0x000ab7d8 -[UIControl touchesEnded:withEvent:] + 458
    9   UIKit                               0x0003eded -[UIWindow _sendTouchesForEvent:] + 567
    10  UIKit                               0x0001fc37 -[UIApplication sendEvent:] + 447
    11  UIKit                               0x00024f2e _UIApplicationHandleEvent + 7576
    12  GraphicsServices                    0x01001992 PurpleEventCallback + 1550
    13  CoreFoundation                      0x00da9944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    14  CoreFoundation                      0x00d09cf7 __CFRunLoopDoSource1 + 215
    15  CoreFoundation                      0x00d06f83 __CFRunLoopRun + 979
    16  CoreFoundation                      0x00d06840 CFRunLoopRunSpecific + 208
    17  CoreFoundation                      0x00d06761 CFRunLoopRunInMode + 97
    18  GraphicsServices                    0x010001c4 GSEventRunModal + 217
    19  GraphicsServices                    0x01000289 GSEventRun + 115
    20  UIKit                               0x00028c93 UIApplicationMain + 1160
    21  UIPickerView_ActionSheet            0x00001cf9 main + 121
    22  UIPickerView_ActionSheet            0x00001c75 start + 53
)
terminate called after throwing an instance of 'NSException'
Current language:  auto; currently objective-c
Welbin
  • 9
  • 4
  • Please include the details of the crash and any crash log that you receive. – jrturton Dec 08 '11 at 14:18
  • @jrturton thank you for your help. I can't upload image yet, please see the last part for crash info. – Welbin Dec 09 '11 at 01:10
  • I would post a link to the photo uploaded to a different host then. Knowing that it crashed on `int retVal = ...` is completely useless. It could literally be _anything_. – Ryan Wersal Dec 09 '11 at 01:29
  • 1
    Also, why are you putting the picker into the menu as a subview? Why not just make another view controller that houses the picker and show it modally instead? – Ryan Wersal Dec 09 '11 at 01:31
  • @Ryan I'm trying to do the same effect as this http://stackoverflow.com/questions/1262574/add-uipickerview-a-button-in-action-sheet-how – Welbin Dec 09 '11 at 04:15
  • @Welbin if you go to the debugger console after the crash and type `bt` (backtrace) this will give useful information, can you do that and update your question? – jrturton Dec 09 '11 at 06:47
  • @jrturton thank you very much for your help. Question was updated as you requested, could you help to check? thanks again. – Welbin Dec 09 '11 at 14:03

1 Answers1

0
[UIPickerView_ActionSheetViewController DatePickerView]: unrecognized selector sent to instance 0x602dfb0

What this tells you is that somewhere you are sending the message DatePickerView to your view controller instance, and it doesn't recognise it.

I can't see such a call anywhere in the code above so it is either in a different file in your project, or you have an old or renamed outlet connection in interface builder. If you have copied this code or some of the resources from somewhere else then you will need to update them to match your actual requirements.

jrturton
  • 118,105
  • 32
  • 252
  • 268
  • thank you so much for your help. The code above is ok, I just created a new project and copied the same code, it worked. There is no DatePickerView in all the files, strange error. – Welbin Dec 09 '11 at 15:24