Skip to content

Instantly share code, notes, and snippets.

@takaokouji
Created January 31, 2012 11:37
Show Gist options
  • Save takaokouji/1710037 to your computer and use it in GitHub Desktop.
Save takaokouji/1710037 to your computer and use it in GitHub Desktop.
MacRubyサンプルプログラム(AppDelegate.rb) - 第53回 Ruby/Rails勉強会@関西 MacRubyではじめる!Macアプリ開発入門
#
# AppDelegate.rb
# Calc
#
# Created by 高尾 宏治 on 12/01/27.
# Copyright 2012 TAKAO Kouji. All rights reserved.
#
class AppDelegate < NSWindowController
attr_accessor :window
attr_accessor :textField
def calc(sender)
string = textField.stringValue
calc = eval(string)
textField.setStringValue(calc.to_s)
end
def applicationDidFinishLaunching(a_notification)
# Insert code here to initialize your application
end
end
#
# AppDelegate.rb
# TextView
#
# Created by 高尾 宏治 on 12/01/27.
# Copyright 2012 TAKAO Kouji. All rights reserved.
#
class AppDelegate
attr_accessor :window
attr_accessor :tableView
def applicationDidFinishLaunching(a_notification)
# Insert code here to initialize your application
end
def numberOfRowsInTableView(aTableView)
# データが何行分あるか返す
return 2
end
def tableView(aTableView, objectValueForTableColumn:aTableColumn, row:rowIndex)
# Table の各セルに表示するデータを返す
# 今回は 2行 x 2列 = 4回、このメソッドが呼び出される
if rowIndex == 0
# 1行目のデータ
case aTableColumn.identifier
when 'name' # 1列目のデータ
str = "Apple"
when 'number' # 2列目のデータ
str = "12"
end
end
if rowIndex == 1
# 2行目のデータ
case aTableColumn.identifier
when 'name' # 1列目のデータ
str = "Orange"
when 'number' # 2列目のデータ
str = "34"
end
end
return str
end
def select(sender)
p tableView.selectedRow
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment