Hey everyone! This tutorial is going to show you how to add a startup view to any of your applications. Many people have been scouring the internet recently looking for ways to add a startup view to their applications. Startup views can be used for many things: Login's, advertisements, Tap To Begin's, etc, they add the possibility to customize your applications without relying on a single view controller to do so. I'm not going to go into the proper Model-View-Controller setup and would appreciate if anyone who knows what their doing lend some helpful advice. Now let's do this!
The first step to adding a startup view to your app is adding the viewcontroller files and xib. In Xcode, click on File, New File, UIView Controller Subclass under the Cocoa Touch Class Tab. You can name your startup view files whatever you'd like, I named mine Startup. It should look like this:
Next what you're going to do is open up the MainViewController.h file and add this to your code:
Note that you're adding the startup view as a subview instead of substituting the actual views. This makes it easier to add as many views as you need, but does have its setbacks. Also note that when you insert the startup view as a subview you have to set the index. The subview index effects how prevalent the Startup view will be in regards to other objects located on the Main View. Try changing the index to 0, 1, 2, or 3 to see what I mean.
Anyways, your MainViewController.m file should look something like this when you add all the code to it:
Now press Build&Go and watch the magic happen! Now you can customize to your hearts desire!
I've attached a copy of the example project I've attached a copy of the example project Here!
Enjoy, and if you have any comments, questions, or concerns, feel free to post here or send me an email anytime. Thanks, and Good Night!
Good question, I chose atIndex:100 to make it the center of attention, say you have 99 items on your screen, if I choose atIndex:98 then 1 of the items will still be in front of the Startup View, whereas atIndex:100 will be first and foremost on your screen. Here is a picture of it:
This picture shows how the Startup View, with the Big Red Button appears to be a part of the Main View, the one with the navigation bar, instead of just a white view with a big red button, the MainView is also a part of it. Try it out and you'll see what I mean.
I read the doc's on Apple and saw it too, you very well could do that but you would have to declare your mainView, I didn't try it but it looks like it would work. Thanks for the comments!
Good question, I chose atIndex:100 to make it the center of attention, say you have 99 items on your screen, if I choose atIndex:98 then 1 of the items will still be in front of the Startup View, whereas atIndex:100 will be first and foremost on your screen. Here is a picture of it:
This picture shows how the Startup View, with the Big Red Button appears to be a part of the Main View, the one with the navigation bar, instead of just a white view with a big red button, the MainView is also a part of it. Try it out and you'll see what I mean.
I read the doc's on Apple and saw it too, you very well could do that but you would have to declare your mainView, I didn't try it but it looks like it would work. Thanks for the comments!
hi Shmoopi, I have just downloaded the example code, one question : how do I create a new view (or subview?) after clicked on the "Yes I did" button on the TabViewViewController? and how do I remove the new view(or subview?) after click a button on the new view? an example code is appreciated
hi Shmoopi, I have just downloaded the example code, one question : how do I create a new view (or subview?) after clicked on the "Yes I did" button on the TabViewViewController? and how do I remove the new view(or subview?) after click a button on the new view? an example code is appreciated
Ok, just follow all the code I have in my tutorial but instead of adding the startup subview in the viewdidload method, try putting it into an IBAction method that's connected to the button you want to switch views with. Hope that helps
Ok, just follow all the code I have in my tutorial but instead of adding the startup subview in the viewdidload method, try putting it into an IBAction method that's connected to the button you want to switch views with. Hope that helps
hi Shmoopi, I've just added code to the button, but the compiler shows errors (see attached image), please could you check this out.. I don't understand what is the problem.
hi Shmoopi, I've just added code to the button, but the compiler shows errors (see attached image), please could you check this out.. I don't understand what is the problem.
The problem is, the subview disappeared because of the last line [self.view remove FromSuperview], how can I keep the last view on the screen and remove the last-1 view?
Good question, I chose atIndex:100 to make it the center of attention, say you have 99 items on your screen, if I choose atIndex:98 then 1 of the items will still be in front of the Startup View, whereas atIndex:100 will be first and foremost on your screen. Here is a picture of it:
This picture shows how the Startup View, with the Big Red Button appears to be a part of the Main View, the one with the navigation bar, instead of just a white view with a big red button, the MainView is also a part of it. Try it out and you'll see what I mean.
I read the doc's on Apple and saw it too, you very well could do that but you would have to declare your mainView, I didn't try it but it looks like it would work. Thanks for the comments!
hi Shmoopi, I have just realized what did you mean to set index to 100, ok, if I click on the BlueView, then the content of TabView will show up, now my question is, if there are 2,3 subviews waiting to be displayed right after BlueView, how can I make the TabView shown up after the 3rd subview is removed? I've tried to use [self.view removeFromSuperview], but it just show up a white view, the buttons, labels on the TabView is not displayed.
hi Shmoopi, I have just realized what did you mean to set index to 100, ok, if I click on the BlueView, then the content of TabView will show up, now my question is, if there are 2,3 subviews waiting to be displayed right after BlueView, how can I make the TabView shown up after the 3rd subview is removed? I've tried to use [self.view removeFromSuperview], but it just show up a white view, the buttons, labels on the TabView is not displayed.
hope you know what I am saying..
I'm actually very confused as to what you're asking I think that you're trying to have 3 subviews show up in order before the mainview shows up. If so, set the one you want to show up first atIndex:100, second atIndex:50, and third atIndex:25. When you want to remove them, just use [self.view removeFromSuperview] in the firstview, secondview, and thirdview .m files. Hope that helps.
I'm actually very confused as to what you're asking I think that you're trying to have 3 subviews show up in order before the mainview shows up. If so, set the one you want to show up first atIndex:100, second atIndex:50, and third atIndex:25. When you want to remove them, just use [self.view removeFromSuperview] in the firstview, secondview, and thirdview .m files. Hope that helps.
Thanks for your reply Shmoopi, actually I've solved the problem after refered to your comment. Now I am back to raise another question Remove subview from another is no more a problem, but what about show up a subview? my question is, since the subview (ex: the index 50th) has been removed fromsuperview, does it mean I need to alloc again in order to show the 50th subview up??
Thanks for your reply Shmoopi, actually I've solved the problem after refered to your comment. Now I am back to raise another question Remove subview from another is no more a problem, but what about show up a subview? my question is, since the subview (ex: the index 50th) has been removed fromsuperview, does it mean I need to alloc again in order to show the 50th subview up??
Yes it does, in order to show it again, you must alloc that spot in memory for it, even if you've already done it once.
Hi Shmoopi,
Thanks for the cool tutorial I am not a newbie to programming but a definite newbie to iPhone app development. So please forgive what to you and others must be an obvious question.
I have a project that allows the user to drill down through several menu levels ending in a nib. The main nib that is loaded seems to spawn from the RootViewController. There is no MainViewController .h or.m. So I don't quite understand where to put the code from this tutorial. The greater part of the drill down code is in the RootViewController.m file
Basically what I am trying to do is insert a nib with with a view (start view) containing a set of buttons which when clicked will load the approbate drill down menus.
Any Help will be greatly appreciated
Dave
Last edited by dfletcher; 02-11-2010 at 02:07 PM.
Reason: It was lame