UITableViewController(Static Cells使用)で、テーブルのセル内に入力欄(UITextField)を設置し、入力欄以外をタップした際にキーボードを消したい。 しかし、ViewController側でタッチイベントを検知していない。 どうやらUITableViewはUIScrollView同様に、タッチイベントをViewControllerまでレスポンダーチェーンさせない。 なので、クラス拡張(SwiftでいうExtension。Objective-Cでいうカテゴリ)で対応させる。 こんな画面。 環境 Xcode 6.3.2 Swift 1.2 UITableViewController TableView - Content:Static Cells Extensionの作成 File -> New -> Fileで、.swiftファイルを作成する 名前は任意
![【Swift】UITableViewのタッチイベントを検知する方法 - mzgkworks](https://cdn-ak-scissors.b.st-hatena.com/image/square/3055889eb09dee23543d1cbd8e1e586a42eded95/height=288;version=1;width=512/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fm%2Fmzgkworks%2F20150702%2F20150702184033.png)