Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Tutorials

Reply
 
LinkBack Thread Tools Display Modes
Old 12-12-2009, 11:56 PM   #1 (permalink)
Shmoopi LLC
 
Shmoopi's Avatar
 
Join Date: Jun 2009
Location: Virginia
Posts: 203
Lightbulb How to Add a Startup View!

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:
Code:
@class Startup;

Startup *startup;

@property (retain, nonatomic) Startup *startup;
Your MainViewController.h file should look like this when you're finished:
Code:
//
//  Add_That_Startup_ScreenViewController.h
//  Add That Startup Screen
//
//  Created by Shmoopi on 12/12/09.
//  Copyright Shmoopi LLC 2009. All rights reserved.
//

#import 

@class Startup;

@interface Add_That_Startup_ScreenViewController : UIViewController {
	Startup *startup;
}
@property (retain, nonatomic) Startup *startup;

@end
Now that you've declared it, it's time to make it show up. In your MainViewController.m file add this code:
Code:
#import "Startup.h"

@synthesize startup;

- (void)loadView {
	if (self.startup == nil) {
		Startup *startupView = [[Startup alloc] initWithNibName:@"Startup" bundle:nil];
		self.startup = startupView;
		[self.view insertSubview:startupView.view atIndex:100];
		[startupView release];
	} else {
		[startup.view removeFromSuperview];
	}
}

- (void)dealloc {
    [super dealloc];
	
	[startup release];
}
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:
Code:
//
//  Add_That_Startup_ScreenViewController.m
//  Add That Startup Screen
//
//  Created by Shmoopi on 12/12/09.
//  Copyright Shmoopi LLC 2009. All rights reserved.
//

#import "Add_That_Startup_ScreenViewController.h"
#import "Startup.h"

@implementation Add_That_Startup_ScreenViewController

@synthesize startup;

- (void)loadView {
	if (self.startup == nil) {
		Startup *startupView = [[Startup alloc] initWithNibName:@"Startup" bundle:nil];
		self.startup = startupView;
		[self.view insertSubview:startupView.view atIndex:100];
		[startupView release];
	} else {
		[startup.view removeFromSuperview];
	}
}

- (void)dealloc {
    [super dealloc];
	
	[startup release];
}

@end
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!

Last edited by Shmoopi; 12-13-2009 at 10:02 AM.
Shmoopi is offline   Reply With Quote
Old 12-13-2009, 08:32 AM   #2 (permalink)
indie dev
 
rocotilos's Avatar
 
Join Date: Oct 2009
Posts: 2,754
Default

Hi Shmoopi, nice tutorial.

But like to ask, why do u use atIndex 100?

how about using this (i never used it tho, but something i read in the doc):
Code:
[self.view insertSubview:startupView.view aboveSubview:mainView];
rocotilos is offline   Reply With Quote
Old 12-13-2009, 10:13 AM   #3 (permalink)
Shmoopi LLC
 
Shmoopi's Avatar
 
Join Date: Jun 2009
Location: Virginia
Posts: 203
Default

Quote:
Originally Posted by rocotilos View Post
Hi Shmoopi, nice tutorial.

But like to ask, why do u use atIndex 100?

how about using this (i never used it tho, but something i read in the doc):
Code:
[self.view insertSubview:startupView.view aboveSubview:mainView];
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!
Shmoopi is offline   Reply With Quote
Old 12-23-2009, 09:19 AM   #4 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 54
Default

Quote:
Originally Posted by Shmoopi View Post
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
Georg is offline   Reply With Quote
Old 12-23-2009, 01:07 PM   #5 (permalink)
Shmoopi LLC
 
Shmoopi's Avatar
 
Join Date: Jun 2009
Location: Virginia
Posts: 203
Default

Quote:
Originally Posted by Georg View Post
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
Shmoopi is offline   Reply With Quote
Old 12-24-2009, 12:37 AM   #6 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 54
Default

Quote:
Originally Posted by Shmoopi View Post
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.
Attached Images
File Type: jpg ???? 2009-12-24 ??1.31.25.jpg (19.0 KB, 1 views)
Georg is offline   Reply With Quote
Old 12-24-2009, 12:40 AM   #7 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 54
Default

Quote:
Originally Posted by Georg View Post
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.
with attachment
Attached Images
File Type: jpg ???? 2009-12-24 ??1.31.25.jpg (61.5 KB, 1 views)
Georg is offline   Reply With Quote
Old 12-24-2009, 12:43 AM   #8 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 54
Default

Quote:
Originally Posted by Georg View Post
with attachment
Submit again,,,,,
Attached Images
File Type: jpg ???? 2009-12-24 ??1.31.25.jpg (61.5 KB, 1 views)
Georg is offline   Reply With Quote
Old 12-24-2009, 01:44 AM   #9 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 54
Default

Quote:
Originally Posted by Georg View Post
Submit again,,,,,

-(IBAction)FirstView;
{

if (self.optionMenu == nil) {
OptionViewController *optionMenuView = [[OptionViewController alloc] initWithNibName:@"OptionViewController" bundle:nil];
self.optionMenu = optionMenuView;
[self.view insertSubviewptionMenuView.view atIndex:99];
[optionMenuView release];
} else {
[optionMenu.view removeFromSuperview];
}
[self.view removeFromSuperview];
}

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?
Georg is offline   Reply With Quote
Old 12-24-2009, 03:27 AM   #10 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 28
Default

I like this tutorial, good pictures and very helpful. Thanks.
iphonedeveloper11 is offline   Reply With Quote
Old 12-24-2009, 04:21 AM   #11 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 54
Default

Quote:
Originally Posted by Shmoopi View Post
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.

hope you know what I am saying..
Georg is offline   Reply With Quote
Old 12-24-2009, 08:55 PM   #12 (permalink)
Shmoopi LLC
 
Shmoopi's Avatar
 
Join Date: Jun 2009
Location: Virginia
Posts: 203
Default

Quote:
Originally Posted by Georg View Post
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.
Shmoopi is offline   Reply With Quote
Old 12-26-2009, 09:46 PM   #13 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 54
Default

Quote:
Originally Posted by Shmoopi View Post
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??
Georg is offline   Reply With Quote
Old 12-27-2009, 11:18 AM   #14 (permalink)
Shmoopi LLC
 
Shmoopi's Avatar
 
Join Date: Jun 2009
Location: Virginia
Posts: 203
Default

Quote:
Originally Posted by Georg View Post
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.
Shmoopi is offline   Reply With Quote
Old 12-28-2009, 12:53 AM   #15 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 54
Default

Quote:
Originally Posted by Shmoopi View Post
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.
Thank you dude, I've solved the problem
Georg is offline   Reply With Quote
Old 02-01-2010, 06:59 PM   #16 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: California
Posts: 1
Default

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
dfletcher is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 244
21 members and 223 guests
ADY, Alsahir, beleg_1998, Dani77, diyora, FAED, fredidf, iDifferent, iph_s, JamesCahall, JasonR, mer10, prchn4christ, Rudy, smithdale87, Speed, spiderguy84, stekki, tgjorgoski, timle8n1, twerner
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,755
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:12 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0