{"id":6855,"date":"2024-06-07T07:20:02","date_gmt":"2024-06-07T07:20:02","guid":{"rendered":"http:\/\/berkut.tech\/?p=6855"},"modified":"2024-06-07T07:45:46","modified_gmt":"2024-06-07T07:45:46","slug":"ios-view-controller-life-cycle","status":"publish","type":"post","link":"https:\/\/berkut.tech\/index.php\/2024\/06\/07\/ios-view-controller-life-cycle\/","title":{"rendered":"iOS View Controller Life Cycle"},"content":{"rendered":"\n<p>Herkese merhabalar arkada\u015flar, 2021 y\u0131l\u0131n\u0131n son yaz\u0131s\u0131 olan View Controller s\u0131n\u0131flar\u0131m\u0131z\u0131n ve uygulamalar\u0131m\u0131z\u0131 yak\u0131ndan etkileyen \u00f6nemli olan bir konuyu Life Cycle(Ya\u015fam D\u00f6ng\u00fcs\u00fc) konusunu detayl\u0131 bir \u015fekilde ele al\u0131yor olaca\u011f\u0131z. Hadi ba\u015flayal\u0131m o zaman.\u00a0<\/p>\n\n\n\n<p id=\"ee4c\">Life Cycle (Ya\u015fam D\u00f6ng\u00fcs\u00fc) uygulamam\u0131z\u0131 geli\u015ftirirken asl\u0131nda dikkat edilmesi gereken \u00f6nemli noktalardan birisidir. K\u0131saca asl\u0131nda ya\u015fam D\u00f6ng\u00fcs\u00fcn\u00fc (Life Cycle) algoritma mant\u0131\u011f\u0131 gibi d\u00fc\u015f\u00fcnebiliriz. Algoritma mant\u0131\u011f\u0131n\u0131n da k\u0131saca bir i\u015flem yap\u0131\u015f s\u0131ras\u0131 vard\u0131r. Uygulama ya\u015fam d\u00f6ng\u00fcs\u00fcnde ise burada da uygulamam\u0131z\u0131n aya\u011fa kalk\u0131\u015f s\u0131ras\u0131nda, ekranlar g\u00f6r\u00fcnd\u00fckten sonra, ekran\u0131m\u0131z kapand\u0131ktan sonra gibi i\u015flem s\u0131ralar\u0131 vard\u0131r temelde uygulam\u0131z\u0131 bu yap\u0131ya g\u00f6re olu\u015ftururuz asl\u0131nda bu konuda iki konu birbirine benzemektedir. Bu y\u00fczden bu konu temel yap\u0131 ta\u015f\u0131n\u0131 olu\u015fturmaktad\u0131r.<\/p>\n\n\n\n<p id=\"c302\">Life Cycle (Ya\u015fam D\u00f6ng\u00fcs\u00fc) ad\u0131ndan da anlayaca\u011f\u0131m\u0131z \u00fczere View Controller i\u00e7erisinde yapmam\u0131z gereken i\u015flemlerin hangi durumlara g\u00f6re ve hangi a\u015famaya g\u00f6re ger\u00e7ekle\u015fmesi gerekti\u011fine karar veren metodlard\u0131r. View Controller ya\u015fam d\u00f6ng\u00fcs\u00fc initialize edilmesi ile ba\u015flamaktad\u0131r. Daha sonra ise View Controller \u0131m\u0131za ait storyboard (ekranlar\u0131m\u0131z\u0131n oldu\u011fu UI, tasar\u0131mlar\u0131m\u0131z) \u00fczerinden olu\u015fturulur.<\/p>\n\n\n\n<p id=\"63a6\">\u015eimdi uygulama i\u00e7erisinde kulland\u0131\u011f\u0131m\u0131z Life Cycle (Ya\u015fam D\u00f6ng\u00fcs\u00fc) methodlar\u0131m\u0131za tek tek inceleyelim.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"6e4f\">loadView<\/h1>\n\n\n\n<p id=\"6896\">K\u0131saca View\u2019\u0131 kod ile olu\u015fturmu\u015f isek o zaman \u00e7a\u011f\u0131rmam\u0131z gereken methoddur. Swift d\u00f6k\u00fcman\u0131n\u0131 inceledi\u011fimizde bu y\u00f6ntemi do\u011frudan \u00e7a\u011f\u0131rmamam\u0131z\u0131 \u00f6neriyor. View Controller da view \u00f6zelli\u011fi \u00e7a\u011f\u0131r\u0131ld\u0131\u011f\u0131nda nil oldu\u011funda bu y\u00f6ntemi \u00e7a\u011f\u0131r\u0131r. Bu method bir g\u00f6r\u00fcn\u00fcm\u00fc y\u00fckler veya olu\u015fturur ve view \u00f6zelli\u011fine atar. loadView View Controller taraf\u0131ndan y\u00f6netilen bir methoddur. View Controller\u2019\u0131n view \u00f6zelli\u011fi daha olu\u015fmam\u0131\u015ft\u0131r ve s\u0131f\u0131rd\u0131r. \u00d6zel bir g\u00f6r\u00fcn\u00fcm olu\u015fturmak ve view \u00f6zelli\u011fine ayarlamak istiyorsak bu y\u00f6ntemi ge\u00e7ersiz k\u0131lmam\u0131z gerekir.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"472\" src=\"https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.40.24-1024x472.png\" alt=\"\" class=\"wp-image-6858\" srcset=\"https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.40.24-1024x472.png 1024w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.40.24-300x138.png 300w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.40.24-768x354.png 768w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.40.24-1536x708.png 1536w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.40.24.png 1670w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"7441\"><strong>viewDidLoad()<\/strong><\/h1>\n\n\n\n<p id=\"e21f\">Bu method yaln\u0131zca bir kez \u00e7a\u011fr\u0131l\u0131r. View Controller\u2019\u0131n view\u2019\u0131 olu\u015fturup storyboard\u2019a y\u00fcklemesi ile \u00e7al\u0131\u015ft\u0131r\u0131l\u0131r. Yani asl\u0131nda t\u00fcm g\u00f6r\u00fcn\u00fcmleri y\u00fckledikten sonra \u00e7a\u011fr\u0131lan bir methoddur. Bu nedenle View Controller\u2019\u0131n view leri olu\u015fturdu\u011fundan outletlerin olu\u015fturuldu\u011fundan eminizdir. Bu k\u0131s\u0131mda dikkat etmemiz gereken baz\u0131 noktalar vard\u0131r bunlar;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>API kullanarak uzun s\u00fcrebilecek ekran\u0131 kitleyecek servis i\u015flemlerinden ka\u00e7\u0131nmam\u0131z gerekir.<\/li>\n\n\n\n<li>Bu method View Controller\u2019\u0131n \u00f6mr\u00fc boyunca sadece bir kez kullan\u0131l\u0131r.<\/li>\n<\/ul>\n\n\n\n<p id=\"9568\">Bu k\u0131s\u0131mda \u00f6nerilenler ise,<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Bir kez ihtiya\u00e7 duyulan a\u011f aramas\u0131<\/li>\n\n\n\n<li>Kullan\u0131c\u0131 aray\u00fcz\u00fc<\/li>\n\n\n\n<li>Bir kez ger\u00e7ekle\u015ftirmemiz gereken i\u015flemler<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"218\" src=\"https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.41.13-1024x218.png\" alt=\"\" class=\"wp-image-6859\" srcset=\"https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.41.13-1024x218.png 1024w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.41.13-300x64.png 300w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.41.13-768x163.png 768w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.41.13-1536x327.png 1536w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.41.13.png 1682w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"f1f6\">viewWillAppear(_ animated: Bool)<\/h1>\n\n\n\n<p id=\"de4b\">Bu method view ekranda g\u00f6sterilmeden hemen \u00f6nce herhangi bir animasyon yap\u0131land\u0131r\u0131lmadan \u00f6nce \u00e7a\u011fr\u0131l\u0131r. Bu method View Controller her g\u00f6r\u00fcnt\u00fclendi\u011finde g\u00f6sterilir. Bu method i\u00e7erisinde de servis i\u015flemlerini, maliyeti y\u00fcksek i\u015flemleri ger\u00e7ekle\u015ftirilmemelidir. Bu method \u00e7a\u011fr\u0131ld\u0131\u011f\u0131nda view s\u0131n\u0131rlar\u0131 \u00e7izilir fakat oryantasyon ayarlanmaz. viewDidLoad dan fark\u0131 View Controller her g\u00f6r\u00fcnd\u00fc\u011f\u00fcnde \u00e7a\u011fr\u0131l\u0131yor olmas\u0131d\u0131r.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" width=\"1024\" height=\"247\" src=\"https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.42.04-1024x247.png\" alt=\"\" class=\"wp-image-6860\" style=\"width:840px;height:auto\" srcset=\"https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.42.04-1024x247.png 1024w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.42.04-300x72.png 300w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.42.04-768x185.png 768w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.42.04-1536x370.png 1536w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.42.04-2048x493.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"c1f3\"><strong>viewDidAppear(_ animated: Bool)<\/strong><\/h1>\n\n\n\n<p id=\"1cff\">Bu method ise view kullan\u0131c\u0131 taraf\u0131ndan g\u00f6r\u00fcld\u00fckten hemen sonra \u00e7a\u011fr\u0131l\u0131r. Bu a\u015famada yine viewWillAppear gibi ekran her g\u00f6sterildi\u011finde \u00e7a\u011fr\u0131lan methoddur. Bu k\u0131s\u0131mda g\u00f6sterilmek istenen animasyonlar, uzun s\u00fcrecek servis i\u015flemleri, konum i\u015flemleri, UserDefaults gibi i\u015flemlerimizi ger\u00e7ekle\u015ftirebiliriz.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"176\" src=\"https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.42.46-1024x176.png\" alt=\"\" class=\"wp-image-6861\" style=\"width:840px;height:auto\" srcset=\"https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.42.46-1024x176.png 1024w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.42.46-300x51.png 300w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.42.46-768x132.png 768w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.42.46-1536x263.png 1536w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.42.46.png 1982w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"bc86\">viewWillDisappear(_ animated: Bool)<\/h1>\n\n\n\n<p id=\"8fca\">Bu method view ekrandan kaybolmak \u00fczereyken \u00e7a\u011fr\u0131lan methoddur. Bu k\u0131s\u0131mda yapaca\u011f\u0131m\u0131z i\u015flemler timer durdurma, servis isteklerini durdurma, klavye gizleme ve veri kayb\u0131na neden olmamak i\u00e7in verilerimizi kaydet gibi i\u015flemlerdir.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"170\" src=\"https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.43.21-1024x170.png\" alt=\"\" class=\"wp-image-6862\" srcset=\"https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.43.21-1024x170.png 1024w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.43.21-300x50.png 300w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.43.21-768x127.png 768w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.43.21-1536x255.png 1536w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.43.21.png 1978w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"9d55\">viewDidDisappear(_ animated: Bool)<\/h1>\n\n\n\n<p id=\"afba\">viewDidDisappear ise view ekrandan kayboldu\u011funda \u00e7a\u011fr\u0131l\u0131r ve art\u0131k view yok olmu\u015ftur. Bu method i\u00e7erisinde de\u011fi\u015fkenlerimizin de\u011ferini s\u0131f\u0131rlayabiliriz ayn\u0131 zamanda bildirimleri sens\u00f6r i\u015flemlerini dinlemeyi durdurmak i\u00e7in bu methodu kullanabiliriz.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"172\" src=\"https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.44.02-1024x172.png\" alt=\"\" class=\"wp-image-6863\" srcset=\"https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.44.02-1024x172.png 1024w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.44.02-300x51.png 300w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.44.02-768x129.png 768w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.44.02-1536x259.png 1536w, https:\/\/berkut.tech\/wp-content\/uploads\/2024\/06\/Ekran-Resmi-2024-06-07-13.44.02.png 1984w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Bug\u00fcn iOS View Controller Life Cycle anlatmaya \u00e7al\u0131\u015ft\u0131m.Umar\u0131m faydal\u0131 olmu\u015ftur. Bir sonraki yaz\u0131da g\u00f6r\u00fc\u015fmek dile\u011fiyle!<\/p>\n\n\n\n<figure class=\"wp-block-pullquote has-text-align-left\"><blockquote><p>Tunahan \u00d6zata\u00e7 | Software Developer<br>Berkut Teknoloji<\/p><\/blockquote><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Herkese merhabalar arkada\u015flar, 2021 y\u0131l\u0131n\u0131n son yaz\u0131s\u0131 olan View Controller s\u0131n\u0131flar\u0131m\u0131z\u0131n ve uygulamalar\u0131m\u0131z\u0131 yak\u0131ndan etkileyen \u00f6nemli olan bir konuyu Life Cycle(Ya\u015fam D\u00f6ng\u00fcs\u00fc) konusunu detayl\u0131 bir \u015fekilde ele al\u0131yor olaca\u011f\u0131z. Hadi ba\u015flayal\u0131m o zaman.\u00a0 Life Cycle (Ya\u015fam D\u00f6ng\u00fcs\u00fc) uygulamam\u0131z\u0131 geli\u015ftirirken asl\u0131nda dikkat edilmesi gereken \u00f6nemli noktalardan birisidir. K\u0131saca asl\u0131nda ya\u015fam D\u00f6ng\u00fcs\u00fcn\u00fc (Life Cycle) algoritma mant\u0131\u011f\u0131 gibi [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,1],"tags":[],"class_list":["post-6855","post","type-post","status-publish","format-standard","hentry","category-software","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/berkut.tech\/index.php\/wp-json\/wp\/v2\/posts\/6855","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/berkut.tech\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/berkut.tech\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/berkut.tech\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/berkut.tech\/index.php\/wp-json\/wp\/v2\/comments?post=6855"}],"version-history":[{"count":2,"href":"https:\/\/berkut.tech\/index.php\/wp-json\/wp\/v2\/posts\/6855\/revisions"}],"predecessor-version":[{"id":6864,"href":"https:\/\/berkut.tech\/index.php\/wp-json\/wp\/v2\/posts\/6855\/revisions\/6864"}],"wp:attachment":[{"href":"https:\/\/berkut.tech\/index.php\/wp-json\/wp\/v2\/media?parent=6855"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/berkut.tech\/index.php\/wp-json\/wp\/v2\/categories?post=6855"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/berkut.tech\/index.php\/wp-json\/wp\/v2\/tags?post=6855"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}