0
2

More than 3 years have passed since last update.

[Swift]Eurekaのリスト選択に独自のViewControllerを利用する

Last updated at Posted at 2020-05-30

背景

先日、ScoreBoxという麻雀成績管理アプリを個人開発してリリースしました。
その中の設定画面ではEurekaを使用しています。
Eurekaは非常にお手軽に設定画面を作成できるのでおすすめです。

悩んだ

麻雀というからには4人(または3人)のプレイヤー選択が必要です。
Eurekaでは決まったリストからのマルチ選択機能は標準で用意されていましたが、
今回はリスト表示後も選択できるプレイヤー数をその場で増減させたかったので工夫が必要でした。

工夫した

だったら自分でプレイヤー選択のViewControllerを自作し、
Eurekaから呼び出そうということでやったのがこちら。
呼び出し先のViewControllerの内容は割愛していますが、Controller内でプレイヤーリストの編集が可能になっています。

<<< ButtonRow() {
    $0.title = "\(game.playerList.count)人 選択中"
    $0.hidden = false
    $0.presentationMode = .show(controllerProvider: ControllerProvider<UIViewController>.callback {
            return playerListVC
        },
        onDismiss: { vc in
            vc.navigationController?.popViewController(animated: true)
        })
    }
    .cellSetup{ (cell, row) in
        cell.imageView?.image = UIImage("アイコン画像")
    }
    .cellUpdate({ (cell, row) in
        cell.textLabel?.text = "\(game.playerList.count)人 選択中"
    })

実際の画面

20200530_173042.GIF

ポイント

$0.presentationMode = .show(controllerProvider: ControllerProvider<UIViewController>.callback {
    return playerListVC
},
onDismiss: { vc in
    vc.navigationController?.popViewController(animated: true)
})

EurekaのButtonRowがタップされた際に表示する自作のViewControllerを指定し、

.cellUpdate({ (cell, row) in
    cell.textLabel?.text = "\(game.playerList.count)人 選択中"
})

自作のViewControllerから戻ってきた場合にButtonRowのキャプションを更新しています。

今後も開発中に工夫した点を残していきたいと思います。(需要が分からないので主に自分への備忘)

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