backwards, to a view controller that was previously on display and to which the user goes back at some point.forward, to any new view controller that comes on the screen and.So, there are only two directions in which data can flow. What matters though is that view controllers come on the screen one after another. In a complex app, there might be many paths that the user can follow. So let’s have a look at how to pass data between view controllers in more detail. When I read that guide years ago, I could not absorb all the concepts. I was surprised to find that the correct information was in there all the time.īut as I often mention, Apple’s documentation is a bit cryptic, and sometimes even wrong (yes, even Apple makes mistakes). Recently, I checked again Apple’s guide on view controllers. So, what makes some techniques better than others?īest practices respect the principles of good software architecture and common design patterns. Nor use notifications, which sank a project, which I had to rescue, for one of my clients. assigning a delegate to a view controllerīut only a few of them are the best practices.įor example, you should not reference view controllers directly, which was the mistake I made in my little game.triggering transitions programmatically in your code.Here are all the ways in which you can pass data between view controllers: If you look at this question on Stack Overflow, you can find pretty much all of them. There are many ways to enable communication between view controllers. In any non-trivial app, view controllers need to communicate and send data back and forth. While in those articles I treated view controller as separate independent entities, they are not. In the past, I wrote about the MVC pattern in iOS and how iOS apps are structured. They go on with the little they know, trying to hack together something and calling it a day.ĭo you want to be a proficient iOS developer? Then you need to understand the ideas behind view controller communication. Good developers know they lack knowledge and take the time to grow it.What is the difference between the few developers that become highly skilled and all the other copy-and-paste developers? The truth is that everybody goes through an initial phase of a poor understanding of the platform. You see, sometimes it is easy to look at someone else’s code and think they are bad developers. When I opened the project, and I looked at the architecture of the app, I wondered: At that point, my experience was much more prominent. Some years later, I wanted to improve my little game and add some new features. So I did what I could with my little experience. It was a new concept for me, and I was not well-versed in software architecture and best practices (they don’t teach those in universities). I was coming from Mac development where there were no view controllers. Like any other iOS developer, I soon came to a roadblock: view controller communication. I read some Apple guides and started coding my app from there. When Apple first published the iOS SDK in 2008, I made a little game for the iPhone. I know first-hand how bad practices can derail a project. I worked with many clients and also built my apps. What happens when you get view controller communication wrong Getting it wrong can lead to hard to fix bugs. Passing data between view controllers might sound like a trivial task.īut when considering that any real iOS app will have many view controllers, communication becomes a crucial part.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |