property myValue : ""
property myPopUp : missing value
on applicationWillFinishLaunching_(aNotification)
tell standardUserDefaults() of current application's NSUserDefaults
registerDefaults_({myValue:myValue})
set myValue to objectForKey_("myValue") as text
end tell
myPopUp's selectItemAtIndex_(myValue - 1)
end applicationWillFinishLaunching_
on myButtonHandler_(sender)
set myValue to (myPopUp's indexOfSelectedItem) + 1 -- This line may be mistake
end myButtonHandler_
on applicationShouldTerminate_(sender)
tell standardUserDefaults() of current application's NSUserDefaults
setObject_forKey_(myValue, "myValue")
end tell
return current application's NSTerminateNow
end applicationShouldTerminate_
我写了这段代码,但是我得到了这个调试错误:
(Project Name)[42733:303] *** -[AppDelegate myButtonHandler:]: Can’t make «class ocid» id «data optr00000000C7FFFFFFFFFFFFFF» into type number. (error -1700)
有谁能告诉我如何修复我的代码?如何避免错误?
答案 0 :(得分:1)
我自己解决了这个问题。
property myValue : ""
property myPopUp : missing value
on applicationWillFinishLaunching_(aNotification)
tell standardUserDefaults() of current application's NSUserDefaults
registerDefaults_({myValue:myValue})
set myValue to objectForKey_("myValue") as text
end tell
myPopUp's selectItemAtIndex_(myValue - 1)
end applicationWillFinishLaunching_
on myButtonHandler_(sender)
set myValue to (myPopUp's indexOfSelectedItem()) + 1 --Here is the mistake
end myButtonHandler_
on applicationShouldTerminate_(sender)
tell standardUserDefaults() of current application's NSUserDefaults
setObject_forKey_(myValue, "myValue")
end tell
return current application's NSTerminateNow
end applicationShouldTerminate_
我应该写indexOfSelectedItem()但是我写了indexOfSelectedItem。