{"id":2514,"date":"2023-01-15T12:11:32","date_gmt":"2023-01-15T09:11:32","guid":{"rendered":"https:\/\/sezeromer.com\/?p=2514"},"modified":"2023-01-15T12:11:32","modified_gmt":"2023-01-15T09:11:32","slug":"uitableview-neden-kullaniriz","status":"publish","type":"post","link":"https:\/\/sezeromer.com\/en\/uitableview-neden-kullaniriz\/","title":{"rendered":"Why Do We Use UITableView?"},"content":{"rendered":"<p>Hello friends, in this article we will talk about why we use dequeueReusableCell in UITableViewCell. You have used UITableView in many projects. In general, I can say that there is no application that is not used. For example; Twitter, Facebook, Instagram etc. It is found on the home page of many applications. So why do we use UITableView? We will find the answers to these questions if we could not do it with UIStackView in ScrollView.<\/p>\r\n<p>There is a UITableView on the home page of many applications that we use in our daily life. We need to display data in list form. Whether it&#8217;s showing products in shopping apps or showing content in social media apps. As you scroll down in these apps, you&#8217;ll see new products or content. While the phone memory should fill up as new content arrives, UITableView handles this very nicely. Depending on the size of the Cell you use in the UITableView, it probably keeps the Cells in RAM while not holding the other Cells. In this way, while scrolling the UITableView, it supports you in RAM management while not having a performance problem.<\/p>\r\n<p>I made my own UITableView in my previous post. Here I was showing 1000 Views on the screen. You can find that article <a href=\"https:\/\/sezeromer.com\/kendi-uitableviewimizi-nasil-olustururuz\/\">here<\/a>. Let&#8217;s do the same scenario using UITableView in another project and look at performance comparisons.<\/p>\r\n<p>I put a UITableView on the screen and set it to be adjacent to every corner of the page.<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-2533\" src=\"https:\/\/sezeromer.com\/wp-content\/uploads\/2022\/12\/Screenshot-2023-01-15-at-11.51.47-1024x588.png\" alt=\"\" width=\"1024\" height=\"588\" srcset=\"https:\/\/sezeromer.com\/wp-content\/uploads\/2022\/12\/Screenshot-2023-01-15-at-11.51.47-1024x588.png 1024w, https:\/\/sezeromer.com\/wp-content\/uploads\/2022\/12\/Screenshot-2023-01-15-at-11.51.47-300x172.png 300w, https:\/\/sezeromer.com\/wp-content\/uploads\/2022\/12\/Screenshot-2023-01-15-at-11.51.47-768x441.png 768w, https:\/\/sezeromer.com\/wp-content\/uploads\/2022\/12\/Screenshot-2023-01-15-at-11.51.47-1536x882.png 1536w, https:\/\/sezeromer.com\/wp-content\/uploads\/2022\/12\/Screenshot-2023-01-15-at-11.51.47.png 2032w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\r\n<p>Then I show 1000 texts on the screen, which you all know simply.<\/p>\r\n<div class=\"wp-block-codemirror-blocks code-block \">\r\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;swift&quot;,&quot;mime&quot;:&quot;text\/x-swift&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">\/\/\r\n\/\/  ViewController.swift\r\n\/\/  table-view-dequeue-reusable-cell\r\n\/\/\r\n\/\/  Created by \u00d6mer Sezer on 15.01.2023.\r\n\/\/\r\n\r\nimport UIKit\r\n\r\nclass ViewController: UIViewController {\r\n\r\n    @IBOutlet private weak var tableView: UITableView! {\r\n        didSet {\r\n            tableView.delegate = self\r\n            tableView.dataSource = self\r\n        }\r\n    }\r\n    \r\n    override func viewDidLoad() {\r\n        super.viewDidLoad()\r\n    }\r\n}\r\n\r\nextension ViewController: UITableViewDelegate {\r\n    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {\r\n        print(\"\\(indexPath.item). selected\")\r\n    }\r\n}\r\n\r\nextension ViewController: UITableViewDataSource {\r\n    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {\r\n        return 1000\r\n    }\r\n    \r\n    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {\r\n        let cell = UITableViewCell()\r\n        cell.textLabel?.text = \"\\(indexPath.item). User\"\r\n        return cell\r\n    }\r\n    \r\n    \r\n}\r\n\r\n<\/pre>\r\n<\/div>\r\n<p>Then I go through the whole list to the end and we can see that the RAM is always 26 MB in size.<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2536\" src=\"https:\/\/sezeromer.com\/wp-content\/uploads\/2023\/01\/2.gif\" alt=\"\" width=\"425\" height=\"917\" \/><\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2537\" src=\"https:\/\/sezeromer.com\/wp-content\/uploads\/2023\/01\/Screenshot-2023-01-15-at-11.57.14.png\" alt=\"\" width=\"284\" height=\"193\" \/><\/p>\r\n<p>When we try a similar scenario with the list I made with UIScrollView and UIStackView, we see that the RAM is constantly increasing and finally 149 MB.<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2538\" src=\"https:\/\/sezeromer.com\/wp-content\/uploads\/2023\/01\/3.gif\" alt=\"\" width=\"425\" height=\"917\" \/><\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2539\" src=\"https:\/\/sezeromer.com\/wp-content\/uploads\/2023\/01\/Screenshot-2023-01-15-at-12.00.26.png\" alt=\"\" width=\"328\" height=\"181\" srcset=\"https:\/\/sezeromer.com\/wp-content\/uploads\/2023\/01\/Screenshot-2023-01-15-at-12.00.26.png 328w, https:\/\/sezeromer.com\/wp-content\/uploads\/2023\/01\/Screenshot-2023-01-15-at-12.00.26-300x166.png 300w\" sizes=\"(max-width: 328px) 100vw, 328px\" \/><\/p>\r\n<p>We understood why we are using UITableView. You can access this project <a href=\"https:\/\/github.com\/omersezer\/swift-projects\/tree\/main\/table-view-dequeue-reusable-cell\">here<\/a>.<\/p>\r\n<p>If you have any questions, you can contact me by commenting or sending an e-mail. Good work.<\/p>\r\n\r\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>Hello friends, in this article we will talk about why we use dequeueReusableCell in UITableViewCell. You have used UITableView in many projects. In general, I can say that there is no application that is not used. For example; Twitter, Facebook, Instagram etc. It is found on the home page of many applications. So why do [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2536,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[327],"tags":[963,115,8,7,964,440,962,328,489,740,566],"class_list":["post-2514","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-swift","tag-dequeue","tag-ios","tag-omer","tag-omer-sezer","tag-reusable","tag-sezer","tag-stack-view","tag-swift","tag-table","tag-uitableview","tag-view"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/2514"}],"collection":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/comments?post=2514"}],"version-history":[{"count":5,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/2514\/revisions"}],"predecessor-version":[{"id":2541,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/2514\/revisions\/2541"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/media\/2536"}],"wp:attachment":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/media?parent=2514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/categories?post=2514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/tags?post=2514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}