2013-03-04 20 views
0

我跟隨Paul Hegarty的CS193P課程視頻(講座#4 @ 1:05:40 mark)並遇到問題。請幫助調試這個'無法識別的選擇器發送到實例'錯誤。視圖有三個對象 - 見圖片(https://docs.google.com/file/d/0B453_F6cDmYzMG1OQW93WVptYUU/edit?usp=sharing無法識別的選擇器發送給Paul Hegarty的CS193P實例

代碼

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

我真的沒有見過到IBAction爲方法直接調用錯誤

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 

回答

0

。 IBAction方法連接到視圖中的動作(按鈕等),並在點擊這些按鈕等時觸發。

如果updateSelectedWord是一個內部方法,只是虛空替換IBAction爲:

(void)updateSelectedWord 

希望這有助於。

+0

謝謝Spectravideo。我試過了,它斷開了步進器。步進似乎需要(IBAction) - 請參閱圖片https://docs.google.com/file/d/0B453_F6cDmYzZVp2M3lZV2loQkU/edit?usp=sharing無論有無更改,仍然有相同的錯誤。 – TaniOS 2013-03-04 12:30:08

+0

爲什麼你有兩個操作連接到值已更改。我會斷開連接並重新連接只有正確的方法。看起來您可能已經更新了IBAction方法名稱,或者您在.h文件中聲明瞭稍微不同的聲明。確保IBAction方法的名稱在.h和.m文件中是相同的,包括是否有任何參數要通過 – Spectravideo328 2013-03-04 12:36:06

+0

我斷開了兩個方法並重新連接了,據說是正確的。它仍然有同樣的問題。最後,我刪除了步進器並重新添加;它的工作原理!不知道爲什麼它以前沒有工作。 :) 謝謝你的幫助。 下面是清理步進器的圖像https://docs.google.com/file/d/0B453_F6cDmYzM29nbUl5b0U5TVE/edit?usp=sharing – TaniOS 2013-03-04 12:58:32

相關問題