0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Swift】TableViewで必要なメソッド

Posted at

##セルの数を決めるメソッド

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
       return セルの数(chatArray.count)
 }

##セルに値を設定するメソッド(以下はチャットアプリ用)

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    //セルを取得する
    let cell = tableView.dequeueReusableCell(withIdentifier: “ID", for: indexPath) as! CustomCell
    //セルに表示する値を設定する
    cell.messageLabel.text = chatArray[indexPath.row].messsage
    cell.userNameLabel.text = chatArray[indexPath.row].sender
    cell.iconImageView.image = UIImage(named: "")
    return cell
}

##セルのセクション数を決めるメソッド

func numberOfSections(in tableView: UITableView) -> Int {
        return セクションの数
}

##セルの高さを決めるメソッド

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
         return view.frame.size.height/6
}

##セルがタップされて時に呼ばれるメソッド

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 
}
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?