以下のコードにおけるsetNeedsLayout
関数について、分からない部分があります。
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "Cell") cell.selectionStyle = .none let profileImageURL = URL(string: self .imageURLStringArray[indexPath.row] as String)! // cell.imageView?.sd_setImage(with:profileImageURL , completed: nil) cell.imageView?.sd_setImage(with: profileImageURL, completed: { (image, error, _, _) in if error == nil{ cell.setNeedsLayout() } }) cell.textLabel!.text = self.titleArray[indexPath.row] cell.detailTextLabel!.text = self.publishedAtArray[indexPath.row] cell.textLabel?.adjustsFontSizeToFitWidth = true cell.detailTextLabel?.adjustsFontSizeToFitWidth = true cell.textLabel?.numberOfLines = 5 cell.detailTextLabel?.numberOfLines = 5 return cell }
公式ドキュメントには、「次の更新サイクル中にレイアウトの更新をトリガーします。」とあるのですが、ここの部分がいまいち分かりません。どなたか、ご解説頂けましたら幸いです。
よろしくお願いします。
次の再レイアウト処理が実行された際に該当箇所の再レイアウトの必要性をセットする関数という解釈では浅くてだめなの?
>該当箇所の再レイアウトの必要性をセットする関数
こちら「再レイアウトの必要性をセットする」といった部分の「必要性をセットする」とはどういった意味なのでしょうか...?
あ、こちらの記事も拝見したのですが、「frame更新要否のフラグを立てる
」とは実際に処理を行うという意味ではないと思うのですが、だとしたら、なんの為にフラグを立てるのかなと疑問だったんですよね...
ついでに更新処理をしてもらうため。
layoutIfNeeded()
→ 今すぐ購買行って焼きそばパン買ってこい!
setNeedsLayout()
→ 購買行くならついでに焼きそばパン買ってきて。
あなたの回答
tips
プレビュー