Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
Bristol
Code:
- (IBAction)cardiac:(id)sender 
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
                                                             delegate:nil
                                                    cancelButtonTitle:nil
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:nil];
    
    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
    
    CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
    
    UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
    pickerView.showsSelectionIndicator = YES;
    pickerView.dataSource = self;
    pickerView.delegate = self;
    
    [actionSheet addSubview:pickerView];
    
    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]];
    closeButton.momentary = YES; 
    closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
    closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
    closeButton.tintColor = [UIColor blackColor];
    [closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];
    [actionSheet addSubview:closeButton];
    
    [actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
    
    [actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
}

The app crashes with [ContentViewController dismissActionSheet:]: unrecognized selector sent to instance 0x6a57bf0, when I select closeButton
 
The app crashes with [ContentViewController dismissActionSheet:]: unrecognized selector sent to instance 0x6a57bf0, when I select closeButton

Because ContentViewController doesn't respond to dismissActionSheet:.

So write a method called that.
 
Does self have a dismissActionSheet: method ?

Error message is quite explicit. You have not given us enough information to tell you what's wrong.
 
What's wrong with the code? Let's make a short list.

1. You didn't tell us what class the posted method is in. Is it the same as the class that was named in the crash? Something else?

2. You didn't say whether it's running in the simulator or the device.

3. You didn't say whether it's running with or without ARC.

4. You didn't say whether it compiles without warnings. If you're ignoring a warning, the answer could easily be right there.

5. You didn't show a stack dump showing what lead to the crash.


This is just a short list of missing information, or extremely simple things to try to debug it.
 
Last edited:
What's wrong with the code? Let's make a short list.

1. You didn't tell us what class the posted method is in. Is it the same as the class that was named in the crash? Something else?

2. You didn't say whether it's running in the simulator or the device.

3. You didn't say whether it's running with or without ARC.

4. You didn't say whether it compiles without warnings. If you're ignoring a warning, the answer could easily be right there.

5. You didn't show a stack dump showing what lead to the crash.


This is just a short list of missing information, or extremely simple things to try to debug it.

1.Yes, same as mentioned in crash
2.simulator
3.running with ARC
4.no warnings
5.I confess I don't know how to debug very well

but I figured out the problem, by changing one small portion of the code

Code:
[closeButton addTarget:actionSheet action:@selector(dismissWithClickedButtonIndex:animated:) forControlEvents:UIControlEventValueChanged];

the picker view does not dismiss with animation, so it seems. it just disappears. i'll try and figure this out.

next time i will post the above observations.
 
...
but I figured out the problem, by changing one small portion of the code

Code:
[closeButton addTarget:actionSheet action:@selector(dismissWithClickedButtonIndex:animated:) forControlEvents:UIControlEventValueChanged];

the picker view does not dismiss with animation, so it seems. it just disappears. i'll try and figure this out.

Honestly, the other replies were far more accurate than mine.


First, do you realize that in your original code, your class needed a method named dismissActionSheet: ? If not, then you haven't figured out the problem, you just avoided that problem by creating a different one.

Did your class have that method? KnightWRX asked that question, but you didn't answer it. If your class didn't have that method, then you'd need to write it. If your class did have method, you didn't show any code for it. The failure might have been because the spelling of the methods was slightly different. No one knows unless you tell us exactly what you did.


Second, the method you're telling closeButton to run for control events needs a specific number and type of parameters.

You can't substitute a one-parameter method with a two-parameter method and expect it to work. Yet that's exactly what your new code does. The method dismissWithClickedButtonIndex:animated: needs two parameters. Is it getting them? What are the parameter values? If you don't know, then you need to study how action sheets in particular use their delegate methods, and also study how methods are defined for delegates.
 
Last edited:
Is it getting them? What are the parameter values? If you don't know, then you need to study how action sheets in particular use their delegate methods, and also study how methods are defined for delegates.

I have studied the delegate and I don't understand. I didn't just copy and paste them at random.

Nevermind. I will keep reading.
 
I have studied the delegate and I don't understand. I didn't just copy and paste them at random.

Nevermind. I will keep reading.

If you expect a useful reply, then you have to describe what it is you don't understand.

Do you understand that the target object needs the method you gave as the selector? In particular, that it needs to actually have the method whose selector you're telling the control to call. Logically, if you tell the control "call this method on that target object", doesn't it make sense that the target object needs to actually have the method you identified?

Maybe you don't have a clear understanding of what a method is, or what a selector means in regard to a method. Or maybe you don't understand how objects have methods, when the code you write is in a class, so perhaps you don't understand the relationship between objects and classes.

I'm just guessing, because you haven't given us anything to go on.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.