作为MacRuby初学者,我正在使用此tutorial,并希望添加一个下拉表,以便在用户尝试从应用中删除条目时发出警告。
遵循代码here,其中Obj-C是
- (IBAction)deleteRecord:(id)sender
{
NSString *title = @"Warning!";
NSString *defaultButton = @"Delete";
NSString *alternateButton = @"Don't Delete";
NSString *otherButton = nil;
NSString *message = @"Are you sure you want to delete the selected record(s)?";
if ( [tableView numberOfSelectedRows] == 0 )
return;
NSBeep();
NSBeginAlertSheet(title, defaultButton, alternateButton, otherButton, mainWindow, self, @selector(sheetDidEnd:returnCode:contextInfo:), nil, nil, message);
}
我在MacRuby:
def removeFriend(sender)
return if @friendsTableView.numberOfSelectedRows == 0
title = 'Warning!'
defaultButton = 'Delete'
alternateButton = 'Don\'t Delete'
otherButton = nil
s = @friendsTableView.numberOfSelectedRows > 1 ? 's' : ''
message = "Are you sure you want to delete the selected record#{s}?"
NSBeginAlertSheet(title, defaultButton, alternateButton, otherButton, @mainWindow, self, :'alertDidEnd:returnCode:contextInfo:', nil, nil, message)
end
和alertDidEnd:returnCode:contextInfo
:
def alertDidEnd(sheet, returnCode:rCode, contextInfo:cInfo)
<array handling code>
end
当此项运行时,我会在点击链接到removeFriend
的按钮时获得一个下拉列表,但如果我点击“删除”,我的应用会崩溃并出现以下错误:
unknown: [BUG] unknown Objective-C immediate: 0x1 (nil)
MacRuby 0.12 (ruby 1.9.2) [universal-darwin10.0, x86_64]
(lldb)
我是否在实施didAlertEnd
方法时出错了,或者这实际上是一个错误?