MacRuby の初心者として、私はこのチュートリアルに取り組んでおり、ユーザーがアプリからエントリを削除しようとしたときに警告するドロップダウン シートを追加したいと考えています。
ここのコードに従うと、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
ますか、それとも実際にはバグですか?