0

我正在关注 Paul Hegarty 的 CS193P 课程视频(第 4 讲 @ 1:05:40 标记)并遇到了问题。请帮助调试此“无法识别的选择器发送到实例”错误。该视图具有三个对象 - 参见图片(https://docs.google.com/file/d/0B453_F6cDmYzMG1OQW93WVptYUU/edit?usp=sharing

编码

    //  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

错误

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
4

1 回答 1

0

我以前真的没有见过直接调用 IBAction 方法。IBAction 方法连接到视图中的操作(按钮等),并在单击这些按钮等时触发。

如果 updateSelectedWord 是内部方法,只需将 IBAction 替换为 void:

(void)updateSelectedWord 

希望这可以帮助。

于 2013-03-04T11:54:34.653 回答