{"id":1138,"date":"2017-10-03T07:30:12","date_gmt":"2017-10-02T22:30:12","guid":{"rendered":"http:\/\/blue-bear.jp\/kb\/?p=1138"},"modified":"2017-10-03T07:30:12","modified_gmt":"2017-10-02T22:30:12","slug":"swift-collectionviewcontroller-xcode9-swift4-%e3%83%86%e3%83%b3%e3%83%97%e3%83%ac%e3%83%bc%e3%83%88","status":"publish","type":"post","link":"https:\/\/blue-bear.jp\/kb\/swift-collectionviewcontroller-xcode9-swift4-%e3%83%86%e3%83%b3%e3%83%97%e3%83%ac%e3%83%bc%e3%83%88\/","title":{"rendered":"[swift] collectionViewController (xcode9 : swift4) \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8"},"content":{"rendered":"<p>collectionViewController (xcode9 : swift4) \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u4e0b\u8a18\u306b\u8a18\u3057\u3066\u304a\u304f<\/p>\n<pre>\r\n\r\nimport UIKit\r\n\r\nclass TestCollectionViewController: UICollectionViewController {\r\n    \r\n    override func viewDidLoad() {\r\n        super.viewDidLoad()\r\n    }\r\n    \r\n    \/\/\u30c7\u30fc\u30bf\u306e\u500b\u6570\u3092\u8fd4\u3059\u30e1\u30bd\u30c3\u30c9\r\n    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {\r\n        return 7\r\n    }\r\n    \r\n    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {\r\n        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: \"TestCell\", for: indexPath as IndexPath)\r\n        let imageView = cell.contentView.viewWithTag(1) as! UIImageView\r\n        imageView.image = UIImage(named: \"image\" + String(indexPath.row) + \".png\")\r\n        \r\n        return cell\r\n    }\r\n    \r\n    override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {\r\n        \/\/\u30bb\u30b0\u30a8\u3092\u5b9f\u884c\u3059\u308b\u3002\r\n        performSegue(withIdentifier: \"TestSegue\", sender: nil)\r\n        print(\"selected\")\r\n    }\r\n    \r\n    \r\n    \r\n    \/\/\u753b\u9762\u9077\u79fb\u5b9f\u884c\u524d\u306e\u547c\u3073\u51fa\u3057\u30e1\u30bd\u30c3\u30c9\r\n    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {\r\n        \/\/\u9078\u629e\u4e2d\u306e\u30bb\u30eb\u306e\u753b\u50cf\u3092\u53d6\u5f97\u3059\u308b\u3002\r\n        let index = collectionView?.indexPathsForSelectedItems\r\n        let cell = collectionView?.cellForItem(at: index![0])\r\n        let imageView = cell!.viewWithTag(1) as! UIImageView\r\n        \r\n        \/\/\u305d\u306e\u4ed6\u306e\u51e6\u7406\r\n    }\r\n    \r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>collectionViewContro<\/p>\n","protected":false},"author":1,"featured_media":88,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/1138"}],"collection":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/comments?post=1138"}],"version-history":[{"count":1,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/1138\/revisions"}],"predecessor-version":[{"id":1139,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/1138\/revisions\/1139"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media\/88"}],"wp:attachment":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media?parent=1138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/categories?post=1138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/tags?post=1138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}