Question

I'm following Paul Hegarty's CS193P course video (lecture #4 @ 1:05:40 mark) and ran into problems. Please help debug this 'unrecognized selector sent to instance' error. The view has three objects - see image (https://docs.google.com/file/d/0B453_F6cDmYzMG1OQW93WVptYUU/edit?usp=sharing)

The code

    //  AttributeViewController.m
    //  Attribute

    #import "AttributeViewController.h"

    @interface AttributeViewController ()
    @property (weak, nonatomic) IBOutlet UILabel *label;                  // collection of words
    @property (weak, nonatomic) IBOutlet UIStepper *selectedWordStepper;  // stepper
    @property (weak, nonatomic) IBOutlet UILabel *selectedWordLabel;      // selected word from label

    @end

    @implementation AttributeViewController

    - (NSArray *)wordList
    {
        NSArray *wordList = [[self.label.attributedText string] componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        if ([wordList count]) {
            return wordList;
        } else {
            return @[@""];
        }
    }

    - (NSString *)selectedWord
    {
        return [self wordList][(int)self.selectedWordStepper.value];
    }

    - (IBAction)updateSelectedWord {
        self.selectedWordStepper.maximumValue = [[self wordList] count]-1;
        self.selectedWordLabel.text = [self selectedWord];
    }

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
        [self updateSelectedWord];
    }

    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }

    @end

The error

2013-03-03 18:03:28.948 Attribute[74205:c07] -[AttributeViewController updateSelectedWord:]: unrecognized selector sent to instance 0x71b93a0
2013-03-03 18:03:28.952 Attribute[74205:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AttributeViewController updateSelectedWord:]: unrecognized selector sent to instance 0x71b93a0'
*** First throw call stack:
(0x1c91012 0x10cee7e 0x1d1c4bd 0x1c80bbc 0x1c8094e 0x10e2705 0x162c0 0x16258 0xd7021 0xd757f 0xd7056 0x42b195 0x42ae91 0xd6696 0x45cef 0x45f02 0x23d4a 0x15698 0x1becdf9 0x1c14f3f 0x1c1496f 0x1c37734 0x1c36f44 0x1c36e1b 0x1beb7e3 0x1beb668 0x12ffc 0x25cd 0x24f5)
libc++abi.dylib: terminate called throwing an exception
(lldb) gdb
Was it helpful?

Solution

I have really not seen direct calls to IBAction methods before. IBAction methods are connected to actions in your View (buttons, etc.) and are triggered when these buttons, etc.. are clicked.

If updateSelectedWord is an internal method, just replace IBAction with void:

(void)updateSelectedWord 

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top