0

作为 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,或者这实际上是一个错误?

4

1 回答 1

1

显然是一个 MacRuby 错误: http: //www.macruby.org/trac/ticket/1368

于 2012-05-09T05:40:18.963 回答