2013-03-11 32 views
0

在我的AppleScriptObjC程序中,我有很多複選框。我有一個腳本,它將每個按鈕的項目標識符作爲字符串循環遍歷。我希望它根據參數激活每個按鈕的setState_方法。總之,我正在尋找這樣的事情:如何使用AppleScriptObjC來更改基於字符串的按鈕的狀態?

set strIdentifier to "button identifier" 
    [magic code here!] 
    strIdentifier's setState_(1) 

任何幫助,將不勝感激!

回答

0

我不認爲有任何'魔術'來做到這一點。我的目的是通過控制你的複選框的父視圖進行迭代,就像這樣:

repeat with aSubview in theParentView's subviews() 
    if aSubview's title()'s isEqualToString_("Check") is not 0 then 
     aSubview's setState_(false) 
    end if 
end repeat 

這裏,theParentView是出口到其中的複選框所在的視圖。 基本上有兩個選項是:

  • 對於每個標識,您遍歷子視圖
  • 您遍歷子視圖一次,並將它們添加到字典,用標識符作爲密鑰。稍後,您可以通過訪問字典訪問複選框。

在第二種情況下,代碼看起來是這樣的:

set aDict to NSMutableDictionary's alloc()'s init() 

repeat with aSubview in theWindow's subviews() 
    aDict's setObject_forKey_(aSubview, aSubview's title()) 
end repeat 

aDict's objectForKey_("Check 1")'s setState_(false) 
相關問題