下記のようにテーブルを表示させて、セル2をタップしたらアクションシートを表示させることをやっているのですが、iPhone5で検証するとセルタップの挙動が不信で行き詰まっています。
下記の手順で動作をチェックすると、アクションシートがうまく表示される場合もありますが、
セル1タップ → セル2タップ
何回か繰り返していると、こんな挙動に見舞われます
セル1タップ → セル2タップ → アクションシートが表示されず、セル外かセル2をもう一度タップで表示
直接セル2を2回タップしてやっと表示される場合もあります。
iPhone 5のiOSは、9.2.1です。
シミュレーター、及びiPhone 6sのiOS 9.2.1の環境でも同様に確認したのですが、こちらは問題ありませんでした。
実装ではカスタムセルを使っています。
Xcode 7.2.1
Swift 2.1
Swift
1//ViewController.swift 2 3import UIKit 4 5class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { 6 7 override func viewDidLoad() { 8 super.viewDidLoad() 9 10 } 11 12 // セクション数 13 func numberOfSectionsInTableView(tableView: UITableView) -> Int { 14 return 1 15 } 16 17 // 行数 18 func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 19 return 2 20 } 21 22 // 表示 23 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 24 // カスタムセル 25 let cell = tableView.dequeueReusableCellWithIdentifier("tableCell") as! TableCell 26 27 if indexPath.section == 0 { 28 if indexPath.row == 0 { 29 cell.textLabel?.text = "セル1" 30 } else if indexPath.row == 1 { 31 cell.textLabel?.text = "セル2" 32 } 33 } 34 35 return cell 36 } 37 38 // セルがタップされた時の処理 39 func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 40 if indexPath.section == 0 { 41 if indexPath.row == 0 { 42 print("セル1") 43 } else if indexPath.row == 1 { 44 showActionSheet() 45 print("セル2") 46 } 47 } 48 } 49 50 func showActionSheet() { 51 let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet) 52 actionSheet.addAction( 53 UIAlertAction(title: "項目1", style: UIAlertActionStyle.Default, handler: {(action) -> Void in 54 }) 55 ) 56 actionSheet.addAction( 57 UIAlertAction(title: "項目2", style: UIAlertActionStyle.Default, handler: {(action) -> Void in 58 }) 59 ) 60 let cancelAction = 61 UIAlertAction(title: "キャンセル", style: UIAlertActionStyle.Cancel, handler: nil) 62 63 actionSheet.addAction(cancelAction) 64 65 self.presentViewController(actionSheet, animated: true, completion: nil) 66 } 67 68 override func didReceiveMemoryWarning() { 69 super.didReceiveMemoryWarning() 70 } 71}
Swift
1// TableCell.swift 2import UIKit 3 4class TableCell: UITableViewCell { 5 6}
自分が持っているiPhone 5の不具合なのかなと考えてしまいますが、何かご存知の方、アドバイスを頂けたらです。
よろしくお願いいたします。
[追記 2016.3.24]
動画でみるとどんな挙動か分かりやすいです。
https://twitter.com/Ojehul/status/712843876868829184
現在、分かっていることは、Storyboard上でTable View CellのSelectionをNoneの設定をしているか、コード上で下記の設定を行うとこの現象が起きるようです。
cell.selectionStyle = UITableViewCellSelectionStyle.None
回答4件
あなたの回答
tips
プレビュー