LoginSignup
0
2

More than 5 years have passed since last update.

【Swift3】xibについて

Last updated at Posted at 2017-09-20

xib

Interface Builderを使ってカスタムパーツを作ることにより各所に使い回すことができる

xibを使用したカスタムビューの作成方法

UITableViewCellをXIBファイルでカスタムセルにする




△注意すること△

xibで作ったcustomCellをtableViewCellに適用させた場合, セルタップからのイベントサイクルが変わるためStoryboardに設定しているSegueが無効になってしまう. それによりカスタムセルを設定すると画面遷移しなくなる.


解決策

didSelectRowAtを使い, cellがタップされた時にsegueを発生させる必要がある


//cellがタップされた時
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        //xibカスタムセル設定によりsegueが無効になっているためsegueを発生させる
        self.performSegue(withIdentifier: "segue名", sender: self.tableView)

    }


参照
- https://www.slideshare.net/satoshianai/xib
- http://qiita.com/yoshikyoto/items/5414546cc2da8be1325e

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2