1
我使用ApplescriptObjc編碼。
我想在一個函數中禁用菜單項「偏好...」,但我不能這樣做。禁用ApplescriptObjc上的菜單項
我可以禁用按鈕。下面是代碼:
myButton's setEnabled_(false)
所以,我試圖禁用就像一個按鈕,菜單項:
myMenuItem's setEnabled_(false)
我看着蘋果的參考(https://developer.apple.com/library/mac/documentation/cocoa/reference/ApplicationKit/Protocols/NSMenuValidation_Protocol/Reference/Reference.html),但我不能用這個引用,因爲我不明白如何禁用它。
- (BOOL)validateMenuItem:(NSMenuItem *)item {
int row = [tableView selectedRow];
if ([item action] == @selector(nextRecord) &&
(row == [countryKeys indexOfObject:[countryKeys lastObject]])) {
return NO;
}
if ([item action] == @selector(priorRecord) && row == 0) {
return NO;
}
return YES;
}
我想我能以這種方式使用此功能:
on validateMenuItem_(myMenuItem)
if myMenuItemIsEnabled = true then
return true
else
return false
end validateMenuItem_
但是,這並不正常工作(不響應)。我如何禁用菜單項?
我會首先添加一個語句,如say in「in validateMenuItem」,以查看此方法是否被調用,並且通過總是返回false來簡化該方法。當我有答案時,我會更多地回覆你(這只是一條評論)。 – Kaydell