完成形の例になっている画像のビューが古い iOS の物でしたが、見た目は質問内で言及されていなかった為
【実現したいこと】
上の図のように1つのテーブルの中に複数のセルがあり、それぞれのセルにはラベルとテキストが入力できるフィールドが入っているデザインにしたい。
上記の部分に絞って回答します。
- Table View Cell の Style を Custom に変更する
- Cell の中に UILabelView と UITextField を配置する
- Auto layout の設定をしてそれぞれのパーツの位置を決める
- UITextField の Border Style を一番左の非表示に変更する
- Table View の Prototype Cells を "2" に変更する
- それぞれの cell のラベルの文字を変更する
- パスワード側の UITextField の Secure Text Entry にチェックを入れる
- それぞれの cell の identifier を任意の物に変更する
- UITableViewController を継承、または Table View 関連の delegate を実装する場所で以下のように書く(indexPath.row == 0 は適当なので状況にあわせて書き換えて下さい)
swift
1override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
2 return 2
3}
4
5override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
6
7 if indexPath.row == 0 {
8 let cell = tableView.dequeueReusableCellWithIdentifier("ID側のidentifier", forIndexPath: indexPath)
9 return cell
10 }else {
11 let cell = tableView.dequeueReusableCellWithIdentifier("パスワード側のidentifier", forIndexPath: indexPath)
12 return cell
13 }
14
15}
16
ex.
Table View の Style を Grouped にすると添付されていた画像のイメージに多少近づくと思います。