LoginSignup
16
8

More than 3 years have passed since last update.

[Swift]TableViewでセルに複数行の文章を表示する方法[ToDoアプリ]

Last updated at Posted at 2018-10-18

はじめに

Qiita初投稿です。
サンプルアプリでよく見るtodoリストのアプリを作成してた際に遭遇した、
セル内の文章が途中から・・・と途切れてしまう際の対処法について
書かせていただきたいと思います。

詳細

tableViewのセルにある程度長い文章を入力すると

Simulator Screen Shot - iPhone XR - 2018-10-18 at 21.45.16.png

この画像のように
・・・で省略されると思います。

対処法

ググると、結構色々な対処法がでてきたのですが、
個人的に一番簡単だったのが、

cell.textLabel?.numberOfLines=0

こちらのコードを、下記の場所にいれてあげる方法です。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell : UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
        cell.textLabel?.numberOfLines=0
        return cell

こうすることで、

Simulator Screen Shot - iPhone XR - 2018-10-18 at 21.48.42.png

上の画像のように途中から・・・と省略されることなく改行され複数行が表示されます。

最後に

最後まで読んでくださりありがとうございました。
もしどなたかの為になれれば、幸いです!!

16
8
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
16
8