Splash Screen With TabBar And TableView In iPhone

This is the TabBar and tableView example . In this example we will see first display the Splash screen later after comes tableview in TabBar controller. So let see how it will work.

Step 1: Open the Xcode, Create a new project using Window Base application. Give the application “TabBarWithTableView”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: We need to add two UIViewController in the class in the project. So select the project -> New File -> Cocoa Touch ->ViewController class and give the class name ”Tableview” and “SecondView”.

Step 4: We need to add background image in the Resource folder.

Step 5: Open the TabBarWithTableViewAppDelegate.h file and make the following changes in the file:

 

#import <uikit/UIKit.h>

@interface TabBarWithTableViewAppDelegate : NSObject <uiapplicationDelegate> {

UITabBarController *tabBarControlller;

}
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarControlller;
@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

 

 

Step 6: Double click the MainWindow.xib file and open it to the Interface Builder.First drag the “Image View” from the library and place it to the window. Select the window and bring up attribute inspector and select the “logo.png”.Drag the TabBarController from the library in the interface builder. First select the first tab from the TabBarController and bring up Identity Inspector and select “TableView” class. Do the same thing for the Second Tab and select “SecondView”. Now save it, close it and go back to the Xcode.

Step 7: In the TabBarWithTableViewAppDelegate.m file and make the following changes in the file:

 

#import "TabBarWithTableViewAppDelegate.h"

@implementation TabBarWithTableViewAppDelegate

@synthesize window=_window,tabBarControlller;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[_window addSubview:tabBarControlller.view];
[self.window makeKeyAndVisible];
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{

}

- (void)applicationDidEnterBackground:(UIApplication *)application
{

}

- (void)applicationWillEnterForeground:(UIApplication *)application
{

}

- (void)applicationDidBecomeActive:(UIApplication *)application
{

}

- (void)applicationWillTerminate:(UIApplication *)application
{

}

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

@end

 

 

Step 8: Open the TableView.h file and make the following changes in the file:

 

#import <uikit/UIKit.h>

@interface TableView : UIViewController <uitableViewDelegate,UITableViewDataSource> {
NSArray *listData;

}

@property(nonatomic,retain) NSArray *listData;

@end

 

 

Step 9: Double click the TableView.xib file open it to the Interface Builder. First drag the Navigation bar from the library and place it to the view. Select the navigation bar from view and bring up Attribute Inspector and change the Title of the Navigation Bar “TableView”. Now drag the TableView from the library and place it to the view . Select the TableView from the view window and bring up Connection Inspector and connect dataSource to the File’s Owner icon and delegate to the File’s Owner icon. Save the .xib file, close it and go back to the Xcode.

Step 10: In the  TableView.m file make the following changes:

 

#import "TableView.h"

@implementation TableView
@synthesize listData;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
NSArray *array = [[NSArray alloc] initWithObjects:@"Sleepy",@"Sneezy",@"Bashful",@"Happy",@"Doc",@"Grumpy",
@"Dopey",@"Thorin",@"Dorin",@"Nori",@"Ori",@"Balin",@"Dwalin",
@"Fili",@"Kili",@"Oin",@"Gloin",@"Bifur",@"Bofur",@"Bombur",nil];

self.listData = array;
[array release];
[super viewDidLoad];
}

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}

- (void)viewDidUnload {

}

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

-(NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [self.listData count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
SimpleTableIdentifier];
if(cell == nil){
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero
reuseIdentifier: SimpleTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:row];
return cell;

}

@end

 

 

Step 11: Double click the SecondView.xib file and open it to the Interface Builder. Select the view and bring up Attribute Inspector and change the background color. Save the .xib file, close it and go back to the Xcode.

Step 12: Now compile and run the application on the simulator.

You can Download SourceCode from here TabBarWithTableView

Leave a Comment:

5 comments
abujaber says June 11, 2011

thank you very much

Reply
AJ says June 22, 2011

I am am absolute amateur in the iOS world, and tried downloading the code to view it, and see it work (as somethings were not working on my code)

I when i tried compiling it, and building it, i got this message “Code Sign error: The identity ‘iPhone Developer’ doesn’t match any valid certificate/private key pair in the default keychain”

Additional assistance would be appreciated.?

Thanks
AJ

Reply
    Sushant says June 23, 2011

    Where you checked this example, device or simulator? If you want to checked the application on the simulator then checked you select iPhone Simulator or OS Device. You need to select iPhone Simulator.
    And another probability, if you select want to run the application on the device then you need to create provisioning Profile for the device from the Apple Developer side. If you have then let us know.

    Reply
roy says October 23, 2011

in some books i see they add
[ tabBarControlller release];
to the
– (void)dealloc
is it important ?

– (void)dealloc
{
[_window release];
[super dealloc];
}

Reply
cft says October 26, 2011

thank you for your example, I am beginner in iphone dev, how I can extend the time of splash screen is showed?

thanks,
cft

Reply
Add Your Reply