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 Reply

Your email address will not be published. Required fields are marked *