Apr 12、2021、TIL(Today I Learned)-閉じ、高次関数
7577 ワード
学習内容
Closure
基本情報
{ (매개변수들) -> 반환 타입 in
실행코드
}



高次関数
1つまたは複数の関数をパラメータとする関数
結果
Map
for文を使用して変更

map高次関数の使用


Filter
for文を使用したフィルタ

filter高次関数の使用


Reduce

reduce高次関数の使用


高次関数フィルタ

サムネイル:

Flat Map or CompactMap

2 D配列を1 Dに展開します.
複数の高次関数のフィルタ:

Q/A
For文とパフォーマンスの違い
サムネイル形式を使用する場合、compileのfor文に比べて遅い場合があります.
難点と解決方法
現在、万国博覧会のメイン画面が博覧会出品目録に切り替わる際、空白目録画面に切り替わる問題がある.明らかにJSONファイルもViewDidLoad()で適切なパーティション化が行われており、tableviewコントローラ、tableviewcellではそれぞれ同じcell識別子が設定されており、cellでは以下のような正しい方法でdequeuが行われている.guard let cell = self.tableView.dequeueReusableCell(withIdentifier: "ItemTableCell", for: indexPath) as? ItemTableViewCell else {
return UITableViewCell()
}
質問1:
問題は以下の方法でセグを推進することである.@IBAction func didTapItemListButton() {
navigationController?.pushViewController(ItemTableViewController(), animated: true)
}
解決方法:感謝@GREEN
これは、XCodeが最初に新しいビューコントローラインスタンスを必要とし、次にどのビューコントローラインスタンスを生成するか分からないため、新しいウィンドウに切り替えていないためです.@IBAction func didTapItemListButton() {
guard let pushViewController = self.storyboard?.instantiateViewController(withIdentifier: "itemTableViewController") as? ItemTableViewController else {
return
}
self.navigationController?.pushViewController(pushViewController, animated: true)
}
コードで書くことができますが、ボタンをマウスでクリックし、ドラッグ&ドロップで簡単にプッシュする方法があります.これはコードをクリアし、より簡単な方法を採用することです.😅
質問2:
博覧会の出展リストの写真と文章はいつもカットされている.そして、なぜこうなったのか分からないが、いつも黄色の警告マークの問題が出ているので、私たちは長い間レスリングをした.
解決策:フクロウに感謝
セル内の画像を拘束する際に、画像サイズを指定し、x軸y軸だけでなく、前後、上、下の3つの拘束を与え、問題点を認識し、x軸とy軸の拘束を解消することで、黄色の警告ウィンドウの問題を解決しました.
また、出品作品の画像サイズは同じにしたいのですが、出品作品の詳細は文字列の長さによってセルの高さを調節しているのですが、アホのように画像のサイズを固定している場合はtopとbottom制約を指定して文章の長さによってセルが大きくなるのでしょうか?画像ビューtop、bottom→content viewのtop、bottom制約をすばやく解消します.self.tableView.rowHeight = UITableView.automaticDimension
self.tableView.estimatedRowHeight = 150
上記のコードは、cellのサイズを動的に設定する場合、cellが予想される高さになっているため、cellの作業量を減らし、親孝行性を向上させたので、使い心地が良いコードだと思って書いておきます.
Reference
この問題について(Apr 12、2021、TIL(Today I Learned)-閉じ、高次関数), 我々は、より多くの情報をここで見つけました
https://velog.io/@inwoodev/Apr-12-2021-TIL-Today-I-Learned-Closure-고차함수
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
guard let cell = self.tableView.dequeueReusableCell(withIdentifier: "ItemTableCell", for: indexPath) as? ItemTableViewCell else {
return UITableViewCell()
}
@IBAction func didTapItemListButton() {
navigationController?.pushViewController(ItemTableViewController(), animated: true)
}
@IBAction func didTapItemListButton() {
guard let pushViewController = self.storyboard?.instantiateViewController(withIdentifier: "itemTableViewController") as? ItemTableViewController else {
return
}
self.navigationController?.pushViewController(pushViewController, animated: true)
}
self.tableView.rowHeight = UITableView.automaticDimension
self.tableView.estimatedRowHeight = 150
Reference
この問題について(Apr 12、2021、TIL(Today I Learned)-閉じ、高次関数), 我々は、より多くの情報をここで見つけました https://velog.io/@inwoodev/Apr-12-2021-TIL-Today-I-Learned-Closure-고차함수テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol