「Ios/swift/TableView/画面遷移」の版間の差分

提供: 初心者エンジニアの簡易メモ
ナビゲーションに移動 検索に移動
ページの作成:「==TableViewで表示されたCellをクリックした後に画面遷移させる方法== Navigationを使った場合のサンプル // Cell が選択された場合...」
 
編集の要約なし
 
3行目: 3行目:
     // Cell が選択された場合
     // Cell が選択された場合
     func tableView(table: UITableView, didSelectRowAtIndexPath indexPath:NSIndexPath) {
     func tableView(table: UITableView, didSelectRowAtIndexPath indexPath:NSIndexPath) {
         _selectedId = self._imgs[indexPath.row].id
         let id: String! = self._imgs[indexPath.row].id
         if _selectedId != nil {
         if id != nil {
             let appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
             let appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
             let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
             let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
             let detailViewController = storyboard.instantiateViewControllerWithIdentifier("DetailViewControllerId") as! DetailViewController
             let detailViewController = storyboard.instantiateViewControllerWithIdentifier("DetailViewControllerId") as! DetailViewController
             detailViewController.selectedId = self._selectedId
             detailViewController.id = id
             appDelegate.navigationController?.pushViewController(detailViewController, animated: false)
             appDelegate.navigationController?.pushViewController(detailViewController, animated: false)
         }
         }
     }
     }

2016年7月5日 (火) 09:41時点における最新版

TableViewで表示されたCellをクリックした後に画面遷移させる方法

Navigationを使った場合のサンプル

   // Cell が選択された場合
   func tableView(table: UITableView, didSelectRowAtIndexPath indexPath:NSIndexPath) {
       let id: String! = self._imgs[indexPath.row].id
       if id != nil {
           let appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
           let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
           let detailViewController = storyboard.instantiateViewControllerWithIdentifier("DetailViewControllerId") as! DetailViewController
           detailViewController.id = id
           appDelegate.navigationController?.pushViewController(detailViewController, animated: false)
       }
   }