Tab Bar Controller'da Navigation Controller gibi birçok ekran arası geçişi sağlar.
Tek farkı bir UIView üzerine birden fazla ekran basabilmemiz.Navigation Controller'da birçok UIView kullandık.
Öncelikle yeni bir proje oluşturuyoruz.
XCode'da oluşturduğumuz projenin görünümü yukarıdaki gibidir.Her görüntülemek için farklı birer Objective-C sınıfı oluşturuyoruz.
Şimdi kodlama kısmına geçelim.
VIEWCONTROLLER.H
//
// ViewController.h
// tabBarAplication
//
// Created by mac on 7/18/13.
// Copyright (c) 2013 mac. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@end
VIEWCONTROLLER.M
//
// ViewController.m
// tabBarAplication
//
// Created by mac on 7/18/13.
// Copyright (c) 2013 mac. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize tabBarController=_tabBarController;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
ViewController sınıfları arasında bir fark yok.Diğer sınıflarıda aynı şekilde kodluyoruz.Uzatmamak için sadece ViewController.h ve ViewController.m sınıflarını yazdım.
APPDELEGATE.H
//
// AppDelegate.h
// tabBarAplication
//
// Created by mac on 7/18/13.
// Copyright (c) 2013 mac. All rights reserved.
//
#import <UIKit/UIKit.h>
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate,UITabBarControllerDelegate>
- (NSArray *)initializeTabBarItems;
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tabBarController;
@end
APPDELEGATE.M
//
// AppDelegate.m
// tabBarAplication
//
// Created by mac on 7/18/13.
// Copyright (c) 2013 mac. All rights reserved.
//
#import "AppDelegate.h"
#import "ViewController.h"
#import "ViewController1.h"
#import "ViewController2.h"
#import "ViewController3.h"
#import "ViewController4.h"
//#import "ViewController5.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize tabBarController = _tabBarController;
- (NSArray *)initializeTabBarItems
{
NSArray * ekranlar;
ViewController * viewController = [[ViewController alloc] init];
ViewController1 * viewController1 = [[ViewController1 alloc] init];
ViewController2 * viewController2 = [[ViewController2 alloc] init];
ViewController3 * viewController3 = [[ViewController3 alloc] init];
ViewController4 * viewController4 = [[ViewController4 alloc] init];
//ViewController5 * viewController5 = [[ViewController5 alloc] init];
viewController.title=@"1.ekran";
viewController1.title=@"2.Ekran";
viewController2.title=@"3.Ekran";
viewController3.title=@"4.Ekran";
viewController4.title=@"5.ekran";
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
UINavigationController * navigationController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
UINavigationController * navigationController2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
UINavigationController * navigationController3 = [[UINavigationController alloc] initWithRootViewController:viewController3];
UINavigationController * navigationController4 = [[UINavigationController alloc] initWithRootViewController:viewController4];
self.window.rootViewController=navigationController;
ekranlar = [NSArray arrayWithObjects:viewController,viewController1,viewController2,viewController3,viewController4,nil];
return (ekranlar);
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
/* Initialize tab bar controller, add tabs controllers */
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [self initializeTabBarItems];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
Hiç yorum yok:
Yorum Gönder