{"id":700,"date":"2020-09-05T22:38:11","date_gmt":"2020-09-05T13:38:11","guid":{"rendered":"https:\/\/naoya-ono.com\/swift\/?p=700"},"modified":"2020-09-15T12:37:23","modified_gmt":"2020-09-15T03:37:23","slug":"swift-tableview-didselectrowat","status":"publish","type":"post","link":"https:\/\/naoya-ono.com\/swift\/swift-tableview-didselectrowat\/","title":{"rendered":"\u3010Swift\u3011UITableView\u306e\u30bb\u30eb\u304c\u30bf\u30c3\u30d7\u3055\u308c\u305f\u6642\u306b\u5225\u306e\u753b\u9762\u3078\u9077\u79fb\u3055\u305b\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u3053\u306e\u30da\u30fc\u30b8\u3067\u306f\u3001UITableView\u306e\u30bb\u30eb\u3092\u30bf\u30c3\u30d7\u3057\u305f\u6642\u306b\u6b21\u306eView\u3078\u9077\u79fb\u3055\u305b\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u524d\u66f8\u3044\u305f\u8a18\u4e8b\u300c<a href=\"https:\/\/naoya-ono.com\/blog\/swift-table-view-basic\/\">UITableView\u306e\u4f7f\u3044\u65b9<\/a>\u300d\u306e\u7d9a\u304d\u3067\u3059\u306e\u3067\u3001\u307e\u3060\u3053\u3061\u3089\u3092\u8aad\u3093\u3067\u7121\u3044\u65b9\u306f\u5148\u306b\u8aad\u3093\u3067\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2 class=\"hh hh5 pastel-bc\" id=\"i-0\">\u5b9f\u88c5\u65b9\u6cd5<\/h2>\n<p>\u30bb\u30eb\u3092\u30bf\u30c3\u30d7\u3057\u305f\u6642\u306e\u51e6\u7406\u306f\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u306e\u300c<strong>extension ViewController: UITableViewDelegate {<\/strong> <strong>}<\/strong>\u300d\u306e\u4e2d\u306b\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>import UIKit\n\nclass ViewController: UIViewController {\n\n  &nbsp; @IBOutlet weak var tableView: UITableView!\n\n  &nbsp; \/\/ 1.\u30bb\u30eb\u306b\u8868\u793a\u3059\u308b\u30c7\u30fc\u30bf\u3092\u6e96\u5099\n&nbsp; &nbsp; var list = [\"\u30bb\u30eb1\", \"\u30bb\u30eb2\", \"\u30bb\u30eb3\", \"\u30bb\u30eb4\", \"\u30bb\u30eb5\"]\n\n&nbsp; &nbsp; override func viewDidLoad() {\n&nbsp; &nbsp; &nbsp; &nbsp; super.viewDidLoad()\n&nbsp; &nbsp; }\n}\n\n\/\/ 2. \u30c6\u30fc\u30d6\u30eb\u30d3\u30e5\u30fc\u306e\u8868\u793a\u306b\u95a2\u9023\u3059\u308b\u51e6\u7406\nextension ViewController: UITableViewDataSource {\n\n  &nbsp; \/\/ 2-1. \u30c6\u30fc\u30d6\u30eb\u306e\u884c\u6570\u3092\u6307\u5b9a\n&nbsp; &nbsp; func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {\n&nbsp; &nbsp; &nbsp; &nbsp; return list.count\n&nbsp; &nbsp; }\n\n&nbsp; &nbsp; \/\/ 2-2. \u30bb\u30eb\u306b\u5024\u3092\u30bb\u30c3\u30c8\n&nbsp; &nbsp; func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {\n\n          \/\/ \u30bb\u30eb\u3092\u53d6\u5f97&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\n&nbsp; &nbsp; &nbsp; &nbsp; let cell = tableView.dequeueReusableCell(withIdentifier: \"sampleCell\", for: indexPath)&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\n\n&nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u30bb\u30eb\u306b\u5024\u3092\u30bb\u30c3\u30c8\n&nbsp; &nbsp; &nbsp; &nbsp; cell.textLabel?.text = list[indexPath.row]\n\n&nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u30bb\u30eb\u3092\u8fd4\u5374\n&nbsp; &nbsp; &nbsp; &nbsp; return cell\n&nbsp; &nbsp; }\n}\n\n\/\/ 3. \u30bb\u30eb\u3092\u30bf\u30c3\u30d7\u3057\u305f\u6642\u306e\u51e6\u7406\u306a\u3069\nextension ViewController: UITableViewDelegate {\n\n}<\/code><\/pre>\n<\/div>\n<p>\u30bb\u30eb\u304c\u30bf\u30c3\u30d7\u3055\u308c\u305f\u6642\u306f<span class=\"keiko_yellow\"><strong>func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)<\/strong><\/span>\u304c\u547c\u3070\u308c\u308b\u305f\u3081\u3001\u6b21\u306e\u3088\u3046\u306b\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>extension ViewController: UITableViewDelegate {\n\n  \/\/ \u30bb\u30eb\u304c\u30bf\u30c3\u30d7\u3055\u308c\u305f\u6642\u306e\u51e6\u7406\n  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {\n    \/\/\u3000\u51e6\u7406\u3092\u8a18\u8ff0\n  }\n\n}<\/code><\/pre>\n<\/div>\n<p>\u5f8c\u306f\u3001\u300c\/\/ \u51e6\u7406\u3092\u8a18\u8ff0\u300d\u306e\u3068\u3053\u308d\u306b\u753b\u9762\u9077\u79fb\u306e\u51e6\u7406\u3092\u66f8\u304f\u3060\u3051\u3067\u3059\u3002<\/p>\n<p>\u306a\u306e\u3067\u6b21\u306e\u3088\u3046\u306b\u66f8\u3051\u3070\u3044\u3044\u3067\u3059\u306d\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>extension ViewController: UITableViewDelegate {\n  \n\/\/ \u30bb\u30eb\u304c\u30bf\u30c3\u30d7\u3055\u308c\u305f\u6642\u306e\u51e6\u7406\n  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {\n<span class=\"token function\" style=\"color: inherit; font-size: 1em;\">    performSegue(withIdentifier: \"toGoNextView\", sender: nil)<\/span>\n  }\n\n} <\/code><\/pre>\n<\/div>\n<p>\u753b\u9762\u9077\u79fb\u306e\u3084\u308a\u65b9\u304c\u3055\u3063\u3071\u308a\u308f\u304b\u3089\u306a\u3044\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u8a18\u4e8b\u3067\u8a73\u3057\u304f\u8aac\u660e\u3057\u3066\u3044\u308b\u306e\u3067\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div id=\"rinkerid180\" class=\"yyi-rinker-contents  yyi-rinker-postid-180 yyi-rinker-img-m yyi-rinker-catid-5 yyi-rinker-catid-10 \">\n<div class=\"yyi-rinker-box\">\n<div class=\"yyi-rinker-image\">\n\t\t\t\t\t\t\t<a href=\"https:\/\/www.amazon.co.jp\/dp\/B086VVQ3DJ?tag=naoya-ono-22&amp;linkCode=ogi&amp;th=1&amp;psc=1\" rel=\"nofollow\" class=\"yyi-rinker-tracking\" data-click-tracking=\"amazon_img 180 \uff3b\u5897\u88dc\u6539\u8a02\u7b2c3\u7248\uff3dSwift\u5b9f\u8df5\u5165\u9580 \u2500\u2500 \u76f4\u611f\u7684\u306a\u6587\u6cd5\u3068\u5b89\u5168\u6027\u3092\u517c\u306d\u5099\u3048\u305f\u8a00\u8a9e WEB+DB PRESS plus\" data-vars-click-id=\"amazon_img 180 \uff3b\u5897\u88dc\u6539\u8a02\u7b2c3\u7248\uff3dSwift\u5b9f\u8df5\u5165\u9580 \u2500\u2500 \u76f4\u611f\u7684\u306a\u6587\u6cd5\u3068\u5b89\u5168\u6027\u3092\u517c\u306d\u5099\u3048\u305f\u8a00\u8a9e WEB+DB PRESS plus\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/m.media-amazon.com\/images\/I\/51iY70Z3fKL._SL160_.jpg\" width=\"113\" height=\"160\" class=\"yyi-rinker-main-img\" style=\"border: none;\"><\/a>\t\t\t\t\t<\/div>\n<div class=\"yyi-rinker-info\">\n<div class=\"yyi-rinker-title\">\n\t\t\t\t\t\t\t\t\t<a href=\"https:\/\/www.amazon.co.jp\/dp\/B086VVQ3DJ?tag=naoya-ono-22&amp;linkCode=ogi&amp;th=1&amp;psc=1\" rel=\"nofollow\" class=\"yyi-rinker-tracking\" data-click-tracking=\"amazon_title 180 \uff3b\u5897\u88dc\u6539\u8a02\u7b2c3\u7248\uff3dSwift\u5b9f\u8df5\u5165\u9580 \u2500\u2500 \u76f4\u611f\u7684\u306a\u6587\u6cd5\u3068\u5b89\u5168\u6027\u3092\u517c\u306d\u5099\u3048\u305f\u8a00\u8a9e WEB+DB PRESS plus\" data-vars-amp-click-id=\"amazon_title 180 \uff3b\u5897\u88dc\u6539\u8a02\u7b2c3\u7248\uff3dSwift\u5b9f\u8df5\u5165\u9580 \u2500\u2500 \u76f4\u611f\u7684\u306a\u6587\u6cd5\u3068\u5b89\u5168\u6027\u3092\u517c\u306d\u5099\u3048\u305f\u8a00\u8a9e WEB+DB PRESS plus\">\uff3b\u5897\u88dc\u6539\u8a02\u7b2c3\u7248\uff3dSwift\u5b9f\u8df5\u5165\u9580 \u2500\u2500 \u76f4\u611f\u7684\u306a\u6587\u6cd5\u3068\u5b89\u5168\u6027\u3092\u517c\u306d\u5099\u3048\u305f\u8a00\u8a9e WEB+DB PRESS plus<\/a>\t\t\t\t\t\t\t<\/div>\n<div class=\"yyi-rinker-detail\">\n<div class=\"credit-box\">created by&nbsp;<a href=\"https:\/\/oyakosodate.com\/rinker\/\" rel=\"nofollow noopener\" target=\"_blank\">Rinker<\/a><\/div>\n<div class=\"price-box\">\n\t\t\t\t\t\t\t<\/div>\n<\/p><\/div>\n<ul class=\"yyi-rinker-links\">\n<li class=\"amazonkindlelink\">\n\t\t\t\t\t\t<a href=\"https:\/\/www.amazon.co.jp\/dp\/B086VVQ3DJ?tag=naoya-ono-22&amp;linkCode=ogi&amp;th=1&amp;psc=1\" rel=\"nofollow\" class=\"yyi-rinker-link yyi-rinker-tracking\" data-click-tracking=\"amazon_kindle 180 \uff3b\u5897\u88dc\u6539\u8a02\u7b2c3\u7248\uff3dSwift\u5b9f\u8df5\u5165\u9580 \u2500\u2500 \u76f4\u611f\u7684\u306a\u6587\u6cd5\u3068\u5b89\u5168\u6027\u3092\u517c\u306d\u5099\u3048\u305f\u8a00\u8a9e WEB+DB PRESS plus\" data-vars-amp-click-id=\"amazon_kindle 180 \uff3b\u5897\u88dc\u6539\u8a02\u7b2c3\u7248\uff3dSwift\u5b9f\u8df5\u5165\u9580 \u2500\u2500 \u76f4\u611f\u7684\u306a\u6587\u6cd5\u3068\u5b89\u5168\u6027\u3092\u517c\u306d\u5099\u3048\u305f\u8a00\u8a9e WEB+DB PRESS plus\">Kindle<\/a>\t\t\t\t\t<\/li>\n<li class=\"amazonlink\">\n\t\t\t\t\t\t<a href=\"https:\/\/www.amazon.co.jp\/dp\/B086VVQ3DJ?tag=naoya-ono-22&amp;linkCode=ogi&amp;th=1&amp;psc=1\" rel=\"nofollow\" class=\"yyi-rinker-link yyi-rinker-tracking\" data-click-tracking=\"amazon 180 \uff3b\u5897\u88dc\u6539\u8a02\u7b2c3\u7248\uff3dSwift\u5b9f\u8df5\u5165\u9580 \u2500\u2500 \u76f4\u611f\u7684\u306a\u6587\u6cd5\u3068\u5b89\u5168\u6027\u3092\u517c\u306d\u5099\u3048\u305f\u8a00\u8a9e WEB+DB PRESS plus\" data-vars-amp-click-id=\"amazon 180 \uff3b\u5897\u88dc\u6539\u8a02\u7b2c3\u7248\uff3dSwift\u5b9f\u8df5\u5165\u9580 \u2500\u2500 \u76f4\u611f\u7684\u306a\u6587\u6cd5\u3068\u5b89\u5168\u6027\u3092\u517c\u306d\u5099\u3048\u305f\u8a00\u8a9e WEB+DB PRESS plus\">Amazon<\/a>\t\t\t\t\t<\/li>\n<li class=\"rakutenlink\">\n\t\t\t\t\t\t<a href=\"https:\/\/hb.afl.rakuten.co.jp\/hgc\/16781883.64066d33.16781884.4f333982\/Rinker_o_20200831130951?pc=https%3A%2F%2Fsearch.rakuten.co.jp%2Fsearch%2Fmall%2Fswift%2B%25E5%25AE%259F%25E8%25B7%25B5%25E5%2585%25A5%25E9%2596%2580%2F%3Ff%3D1%26grp%3Dproduct&amp;m=https%3A%2F%2Fsearch.rakuten.co.jp%2Fsearch%2Fmall%2Fswift%2B%25E5%25AE%259F%25E8%25B7%25B5%25E5%2585%25A5%25E9%2596%2580%2F%3Ff%3D1%26grp%3Dproduct\" rel=\"nofollow\" class=\"yyi-rinker-link yyi-rinker-tracking\" data-click-tracking=\"rakuten 180 \uff3b\u5897\u88dc\u6539\u8a02\u7b2c3\u7248\uff3dSwift\u5b9f\u8df5\u5165\u9580 \u2500\u2500 \u76f4\u611f\u7684\u306a\u6587\u6cd5\u3068\u5b89\u5168\u6027\u3092\u517c\u306d\u5099\u3048\u305f\u8a00\u8a9e WEB+DB PRESS plus\" data-vars-amp-click-id=\"rakuten 180 \uff3b\u5897\u88dc\u6539\u8a02\u7b2c3\u7248\uff3dSwift\u5b9f\u8df5\u5165\u9580 \u2500\u2500 \u76f4\u611f\u7684\u306a\u6587\u6cd5\u3068\u5b89\u5168\u6027\u3092\u517c\u306d\u5099\u3048\u305f\u8a00\u8a9e WEB+DB PRESS plus\">\u697d\u5929\u5e02\u5834<\/a>\t\t\t\t\t<\/li>\n<li class=\"yahoolink\">\n\t\t\t\t\t\t<a href=\"https:\/\/shopping.yahoo.co.jp\/search?p=swift+%E5%AE%9F%E8%B7%B5%E5%85%A5%E9%96%80\" rel=\"nofollow\" class=\"yyi-rinker-link yyi-rinker-tracking\" data-click-tracking=\"yahoo 180 \uff3b\u5897\u88dc\u6539\u8a02\u7b2c3\u7248\uff3dSwift\u5b9f\u8df5\u5165\u9580 \u2500\u2500 \u76f4\u611f\u7684\u306a\u6587\u6cd5\u3068\u5b89\u5168\u6027\u3092\u517c\u306d\u5099\u3048\u305f\u8a00\u8a9e WEB+DB PRESS plus\" data-vars-amp-click-id=\"yahoo 180 \uff3b\u5897\u88dc\u6539\u8a02\u7b2c3\u7248\uff3dSwift\u5b9f\u8df5\u5165\u9580 \u2500\u2500 \u76f4\u611f\u7684\u306a\u6587\u6cd5\u3068\u5b89\u5168\u6027\u3092\u517c\u306d\u5099\u3048\u305f\u8a00\u8a9e WEB+DB PRESS plus\">Yahoo\u30b7\u30e7\u30c3\u30d4\u30f3\u30b0<\/a>\t\t\t\t\t<\/li>\n<\/ul><\/div>\n<\/p><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u306e\u30da\u30fc\u30b8\u3067\u306f\u3001UITableView\u306e\u30bb\u30eb\u3092\u30bf\u30c3\u30d7\u3057\u305f\u6642\u306b\u6b21\u306eView\u3078\u9077\u79fb\u3055\u305b\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002 \u4ee5\u524d\u66f8\u3044\u305f\u8a18\u4e8b\u300cUITableView\u306e\u4f7f\u3044\u65b9\u300d\u306e\u7d9a\u304d\u3067\u3059\u306e\u3067\u3001\u307e\u3060\u3053\u3061\u3089\u3092\u8aad\u3093\u3067\u7121\u3044\u65b9\u306f\u5148\u306b\u8aad\u3093\u3067\u304a\u3044\u3066\u304f\u3060 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":702,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,10],"tags":[],"_links":{"self":[{"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/posts\/700"}],"collection":[{"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/comments?post=700"}],"version-history":[{"count":1,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/posts\/700\/revisions"}],"predecessor-version":[{"id":701,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/posts\/700\/revisions\/701"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/media\/702"}],"wp:attachment":[{"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/media?parent=700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/categories?post=700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/tags?post=700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}