{"id":1416,"date":"2022-03-11T20:44:08","date_gmt":"2022-03-11T11:44:08","guid":{"rendered":"https:\/\/www.typea.info\/blog\/?p=1416"},"modified":"2022-03-12T18:05:52","modified_gmt":"2022-03-12T09:05:52","slug":"nstableview_celbased","status":"publish","type":"post","link":"https:\/\/www.typea.info\/blog\/index.php\/2022\/03\/11\/nstableview_celbased\/","title":{"rendered":"NSTableView CellBased\u3092\u8a66\u3057\u3066\u307f\u308b(macos)"},"content":{"rendered":"<p><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2022\/03\/08\/xamarin_mac_app_storyboard\/\">Xamarin.Mac + storyboard\u3067\u3001XCode(Interface Builder)\u3067UI\u4f5c\u3063\u3066\u3001\u30ed\u30b8\u30c3\u30af\u306f\u624b\u6163\u308c\u305fC#<\/a>\u3067\u3068\u304b\u601d\u3063\u3066\u3044\u308b\u306e\u3060\u304c\u3001NSApplication.ModalResponse.OK \u304c\u3001C#\u5074\u3067\u898b\u3064\u304b\u3089\u306a\u304f\u3066\u5c11\u3057\u840e\u3048\u305f\u306e\u3068\u3001\u305d\u3082\u305d\u3082storyboard\u306e\u4f7f\u3044\u65b9\u304c\u3088\u304f\u308f\u304b\u3089\u306a\u3044\u306e\u3067\u3001NSTableView\u306eCellBased(\u3042\u3068\u3001ViewBased\u304c\u3042\u308b\u307f\u305f\u3044)\u3092\u5b9f\u88c5\u3057\u306a\u304c\u3089\u3001\u5c11\u3057\u6163\u308c\u308b\u3002<\/p>\n<p><a href=\"https:\/\/developer.apple.com\/library\/archive\/documentation\/Cocoa\/Conceptual\/TableView\/PopulatingCellTables\/PopulatingCellTables.html\">Working with NSCell-Based Table Views (apple.com)<\/a><\/p>\n<h2>1.Table View\u3092ViewController\u306b\u8ffd\u52a0<\/h2>\n<p>+\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3068\u30b3\u30de\u30f3\u30c9\u30d1\u30ec\u30c3\u30c8\u7684\u306a\u3082\u306e\u304c\u958b\u304f(XCode\u3053\u306e\u3042\u305f\u308a\u306e\u540d\u524d\u304c\u3088\u304f\u308f\u304b\u3089\u306a\u3044\u306e\u3067\u8f9b\u3044\u3001\u3001\u3001\u30d0\u30fc\u30b8\u30e7\u30f3\u4e0a\u304c\u3063\u3066\u30a2\u30a4\u30b3\u30f3\u5909\u308f\u3063\u3066\u305f\u308a)\u306e\u3067\u3001Table View \u3092\u691c\u7d22\u3057\u3001\u30c9\u30ed\u30c3\u30d7\u3059\u308b\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/tool_lib.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"tool_lib.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/tool_lib.png\" alt=\"Tool lib\" width=\"164\" height=\"93\" border=\"0\"><\/a><\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00001.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"nstableview_celbased00001.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00001.png\" alt=\"Nstableview celbased00001\" width=\"599\" height=\"390\" border=\"0\"><\/a><\/p>\n<p>Table View\u3092\u9078\u629e\u3057\u3001Attributes Inspector \u306e\u30a2\u30a4\u30b3\u30f3\u3092\u9078\u629e\u3057\u3001Content Mode \u3092 Cell Based\u306b<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00002.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"nstableview_celbased00002.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00002.png\" alt=\"Nstableview celbased00002\" width=\"600\" height=\"375\" border=\"0\"><\/a><\/p>\n<p>\u30ab\u30e9\u30e0\u304c\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u30012\u5217\u4f5c\u3089\u308c\u308b\u306e\u3067\u3001\u305d\u308c\u305e\u308c\u306b\u3001Identity Inspector \u30a2\u30a4\u30b3\u30f3\u3092\u9078\u629e\u3057\u3001ID\u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n<p>\u30ab\u30e9\u30e0\u6570\u3092\u5909\u3048\u308b\u3068\u304d\u306b\u306f\u3001Attributes Inspector \u306e Columns \u306e\u6570\u5024\u3092\u5909\u3048\u308b\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00003.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"nstableview_celbased00003.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00003.png\" alt=\"Nstableview celbased00003\" width=\"599\" height=\"348\" border=\"0\"><\/a><\/p>\n<p>\u540c\u69d8\u306b2\u5217\u76ee\u306eID\u3082\u8a2d\u5b9a<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00004.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"nstableview_celbased00004.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00004.png\" alt=\"Nstableview celbased00004\" width=\"599\" height=\"357\" border=\"0\"><\/a><\/p>\n<h2>2.DataSource\u3068Delegate\u306e\u30d0\u30a4\u30f3\u30c9<\/h2>\n<p>Table View\u3092control\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u306a\u304c\u3089\u3001View Controller \u3078\u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00006.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"nstableview_celbased00006.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00006.png\" alt=\"Nstableview celbased00006\" width=\"599\" height=\"464\" border=\"0\"><\/a><\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2022\/03\/08\/xamarin_mac_app_storyboard\/\">Outlets<\/a>\u3067\u3001dataSource\u304a\u3088\u3073delegate\u3092\u9078\u629e\u3059\u308b\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00007.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"nstableview_celbased00007.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00007.png\" alt=\"Nstableview celbased00007\" width=\"599\" height=\"496\" border=\"0\"><\/a><\/p>\n<p>ViewController\u3068\u9023\u643a\u3055\u308c\u305f\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00008.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"nstableview_celbased00008.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00008.png\" alt=\"Nstableview celbased00008\" width=\"599\" height=\"412\" border=\"0\"><\/a><\/p>\n<p>\u30b3\u30fc\u30c9\u304b\u3089\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092ViewController.swift\u306b\u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7\u3057\u3066\u3001<a href=\"https:\/\/www.typea.info\/blog\/index.php\/2022\/03\/08\/xamarin_mac_app_storyboard\/\">Outlet<\/a>\u3092\u4f5c\u6210\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00009.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"nstableview_celbased00009.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00009.png\" alt=\"Nstableview celbased00009\" width=\"746\" height=\"333\" border=\"0\"><\/a><\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00010.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"nstableview_celbased00010.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00010.png\" alt=\"Nstableview celbased00010\" width=\"599\" height=\"356\" border=\"0\"><\/a><\/p>\n<h2>3.\u30bd\u30fc\u30b9<\/h2>\n<p>\u4e0a\u56f3\u3067\u3001\u30c9\u30e9\u30c3\u30b0&amp;\u30c9\u30ed\u30c3\u30d7\u3067\u30b3\u30fc\u30c9\u751f\u6210\u3057\u305f\u308a\u3057\u3066\u3044\u308b\u306e\u3060\u3051\u308c\u3069\u3001\u30d7\u30ed\u30c8\u30b3\u30eb\u306e\u5ba3\u8a00\u306f\u81ea\u52d5\u3067\u3055\u308c\u306a\u3044\u306e\u304b\u3057\u3089\uff1f<\/p>\n<p>\u624b\u52d5\u3067NSTableViewDelegate, NSTableViewDataSource\u3092\u5b9f\u88c5\u3001<\/p>\n<ul>\n<li>rows \uff1a\u30c0\u30df\u30fc\u30c7\u30fc\u30bf<\/li>\n<li>viewDidLoad\uff1a\u30c0\u30df\u30fc\u30c7\u30fc\u30bf\u3092\u8a70\u3081\u308b<\/li>\n<li>numberOfRows\uff1a\u30c0\u30df\u30fc\u30c7\u30fc\u30bf\u4ef6\u6570<\/li>\n<li>tableView\uff1a\u30c0\u30df\u30fc\u30c7\u30fc\u30bf\u306e\u30bb\u30eb\u5024\u3092\u8fd4\u3059<\/li>\n<\/ul>\n<pre class=\"prettyprint\">import Cocoa\n\nclass ViewController: NSViewController, NSTableViewDelegate, NSTableViewDataSource  {\n\n    @IBOutlet weak var tblView: NSTableView!\n    @IBOutlet weak var tblCol1: NSTableColumn!\n    @IBOutlet weak var tblCol2: NSTableColumn!\n    \n    var rows : [NSDictionary] = []\n    \n    func numberOfRows(in tableView: NSTableView) -&gt; Int {\n        return self.rows.count;\n    }\n\n    func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -&gt; Any? {\n        return rows[row][(tableColumn?.identifier)!]\n    }\n    \n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        \/\/ Do any additional setup after loading the view.\n        for i in 0 ..&lt; 10 {\n            rows.append(NSDictionary(dictionary: [\"tblCol1\": \"Col1-\\(i)\", \"tblCol2\": \"Col2-\\(i)\"]))\n        }\n        self.tblView.reloadData();\n    }\n\n    override var representedObject: Any? {\n        didSet {\n        \/\/ Update the view, if already loaded.\n        }\n    }\n}\n<\/pre>\n<h2>4.\u5b9f\u884c<\/h2>\n<p>\u3068\u308a\u3042\u3048\u305a\u8868\u793a\u3067\u304d\u305f\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00011.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"nstableview_celbased00011.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/03\/nstableview_celbased00011.png\" alt=\"Nstableview celbased00011\" width=\"599\" height=\"377\" border=\"0\"><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Xamarin.Mac + storyboard\u3067\u3001XCode(Interface Builder)\u3067UI\u4f5c\u3063\u3066\u3001\u30ed\u30b8\u30c3\u30af\u306f\u624b\u6163\u308c\u305fC#\u3067\u3068\u304b\u601d\u3063\u3066\u3044\u308b\u306e\u3060\u304c\u3001NSApplication.ModalResponse.OK [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1415,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","footnotes":""},"categories":[170,127,126,1],"tags":[169,130],"class_list":["post-1416","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cocoa","category-swift","category-xcode","category-undefined","tag-cocoa","tag-swift"],"veu_head_title_object":{"title":"","add_site_title":""},"_links":{"self":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1416"}],"version-history":[{"count":3,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1416\/revisions"}],"predecessor-version":[{"id":1434,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1416\/revisions\/1434"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/media\/1415"}],"wp:attachment":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}