posted by 프띠버리 2013. 8. 26. 17:42

AppDelegate.h

//

//  AppDelegate.h

//  TableVieww

//

//  Created by Lab10 on 13. 8. 21..

//  Copyright (c) 2013 Lab10. All rights reserved.

//


#import <UIKit/UIKit.h>


@class RootViewController;


@interface AppDelegate : UIResponder <UIApplicationDelegate>

{

    UINavigationController *navigationController;

}


@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) UINavigationController *navigationController;


@end



AppDelegate.m

#import "AppDelegate.h"


//#import "ViewController.h"

#import "RootViewController.h"


@implementation AppDelegate

@synthesize window;

@synthesize navigationController;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    // 애플리케이션 시작 수행될 개발자가 원하는 코드를 추가하는 부분

    UIViewController *rootController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];

    navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    [self.window addSubview:navigationController.view];

    

    [self.window makeKeyAndVisible];

    return YES;

}



RootViewController.h



#import <UIKit/UIKit.h>

@class BooksViewController;

@interface RootViewController : UITableViewController

{

    NSArray *authorList;

    BooksViewController *booksController;

}


@property (strong, nonatomic) NSArray *authorList;

@property (strong, nonatomic) IBOutlet BooksViewController *booksController;


@end



RootViewController.m

#import "RootViewController.h"

#import "BooksViewController.h"


@interface RootViewController ()


@end


@implementation RootViewController

@synthesize authorList;

@synthesize booksController;


- (id)initWithStyle:(UITableViewStyle)style

{

    self = [super initWithStyle:style];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

    self.authorList = [[NSArray alloc] initWithObjects:@"1", @"2", @"3", nil];

    self.title = @"Month";

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

}


#pragma mark - Table view data source


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return 1;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return [self.authorList count];

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }

    

    cell.textLabel.text = [self.authorList objectAtIndex:[indexPath row]];

    

    return cell;

}


#pragma mark - Table view delegate


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    if(0 == indexPath.row)

    {

        self.booksController.title = @"1";

    }

    else if(1 == indexPath.row)

    {

        self.booksController.title = @"2";

    }

    else

    {

        self.booksController.title = @"3";

    }

    

    [self.navigationController pushViewController:self.booksController animated:YES];

}


@end



BooksViewController.h


#import <UIKit/UIKit.h>

@class NiceViewController;

@interface BooksViewController : UITableViewController

{

    NSArray *books;

    NiceViewController *niceController;

}

@property (strong, nonatomic) NSArray *books;

@property (strong, nonatomic) IBOutlet NiceViewController *niceController;


@end



BooksViewController.m


#import "BooksViewController.h"

#import "NiceViewController.h"


@interface BooksViewController ()


@end


@implementation BooksViewController

@synthesize books;

@synthesize niceController;


- (id)initWithStyle:(UITableViewStyle)style

{

    self = [super initWithStyle:style];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [super viewDidLoad];


}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

}


#pragma mark - Table view data source


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return 1;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return [books count];

}


- (void)viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

    if([self.title isEqualToString:@"1"])

    {

        books = [[NSArray alloc] initWithObjects:@"1 1", @"1 2", @"1 3", @"1 4", @"1 5", @"1 6", nil];

    }

    else if([self.title isEqualToString:@"2"])

    {

        books = [[NSArray alloc] initWithObjects:@"2 1", @"2 2", @"2 3", @"2 4", @"2 5", nil];

    }

    else

    {

        books = [[NSArray alloc] initWithObjects:@"3 1", @"3 2", @"3 3", @"3 4", @"3 5", @"3 6", nil];

    }


    [self.tableView reloadData];

    

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }

    

    cell.textLabel.text = [books objectAtIndex:[indexPath row]];

    

    return cell;

}



#pragma mark - Table view delegate


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    if([self.title isEqualToString:@"1"])

    {

        if(0 == indexPath.row)

        {

            self.niceController.title = @"1 1";

        }

        else if(1 == indexPath.row)

        {

            self.niceController.title = @"1 2";

        }

        else if(2 == indexPath.row)

        {

            self.niceController.title = @"1 3";

        }

        else if(3 == indexPath.row)

        {

            self.niceController.title = @"1 4";

        }

        else if(4 == indexPath.row)

        {

            self.niceController.title = @"1 5";

        }

        else

        {

            self.niceController.title = @"1 6";

        }

    }

    else if([self.title isEqualToString:@"2"])

    {

        if(0 == indexPath.row)

        {

            self.niceController.title = @"2 1";

        }

        else if(1 == indexPath.row)

        {

            self.niceController.title = @"2 2";

        }

        else if(2 == indexPath.row)

        {

            self.niceController.title = @"2 3";

        }

        else if(3 == indexPath.row)

        {

            self.niceController.title = @"2 4";

        }

        else

        {

            self.niceController.title = @"2 5";

        }

    }

    else

    {

        if(0 == indexPath.row)

        {

            self.niceController.title = @"3 1";

        }

        else if(1 == indexPath.row)

        {

            self.niceController.title = @"3 2";

        }

        else if(2 == indexPath.row)

        {

            self.niceController.title = @"3 3";

        }

        else if(3 == indexPath.row)

        {

            self.niceController.title = @"3 4";

        }

        else if(4 == indexPath.row)

        {

            self.niceController.title = @"3 5";

        }

        else

        {

            self.niceController.title = @"3 6";

        }

    }


    [self.navigationController pushViewController:self.niceController animated:YES];

}

@end



NiceViewController.h

#import <UIKit/UIKit.h>


@interface NiceViewController : UITableViewController

{

    NSArray *nice;

}


@property (strong, nonatomic) NSArray *nice;


@end



NiceViewController.m

#import "NiceViewController.h"


@interface NiceViewController ()


@end


@implementation NiceViewController

@synthesize nice;


- (id)initWithStyle:(UITableViewStyle)style

{

    self = [super initWithStyle:style];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

    

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

}


#pragma mark - Table view data source


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return 1;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return [nice count];

}


- (void)viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

    if([self.title isEqualToString:@"1 1"])

    {

         nice = [[NSArray alloc] initWithObjects:@"1kg", @"1cm", @"1", @"", nil];

    }

    else if([self.title isEqualToString:@"1 2"])

    {

        nice = [[NSArray alloc] initWithObjects:@"2kg", @"2cm", @"2", @"", nil];

    }

    else if([self.title isEqualToString:@"1 3"])

    {

        nice = [[NSArray alloc] initWithObjects:@"3kg", @"3cm", @"3", @"", nil];

    }

    else if([self.title isEqualToString:@"1 4"])

    {

        nice = [[NSArray alloc] initWithObjects:@"4kg", @"4cm", @"4", @"", nil];

    }

    else if([self.title isEqualToString:@"1 5"])

    {

        nice = [[NSArray alloc] initWithObjects:@"5kg", @"5cm", @"5", @"", nil];

    }

    else if([self.title isEqualToString:@"1 6"])

    {

        nice = [[NSArray alloc] initWithObjects:@"6kg", @"6cm", @"6", @"", nil];

    }

    else if([self.title isEqualToString:@"2 1"])

    {

        nice = [[NSArray alloc] initWithObjects:@"7kg", @"7cm", @"7", @"", nil];

    }

    else if([self.title isEqualToString:@"2 2"])

    {

        nice = [[NSArray alloc] initWithObjects:@"8kg", @"8cm", @"8", @"", nil];

    }

    else if([self.title isEqualToString:@"2 3"])

    {

        nice = [[NSArray alloc] initWithObjects:@"9kg", @"9cm", @"9", @"", nil];

    }

    else if([self.title isEqualToString:@"2 4"])

    {

        nice = [[NSArray alloc] initWithObjects:@"10kg", @"10cm", @"10", @"", nil];

    }

    else if([self.title isEqualToString:@"2 5"])

    {

        nice = [[NSArray alloc] initWithObjects:@"11kg", @"11cm", @"10", @"", nil];

    }

    else if([self.title isEqualToString:@"3 1"])

    {

        nice = [[NSArray alloc] initWithObjects:@"12kg", @"12cm", @"11", @"", nil];

    }

    else if([self.title isEqualToString:@"3 2"])

    {

        nice = [[NSArray alloc] initWithObjects:@"13kg", @"13cm", @"12", @"", nil];

    }

    else if([self.title isEqualToString:@"3 3"])

    {

        nice = [[NSArray alloc] initWithObjects:@"14kg", @"14cm", @"13", @"", nil];

    }

    else if([self.title isEqualToString:@"3 4"])

    {

        nice = [[NSArray alloc] initWithObjects:@"15kg", @"15cm", @"14", @"", nil];

    }

    else if([self.title isEqualToString:@"3 5"])

    {

        nice = [[NSArray alloc] initWithObjects:@"16kg", @"16cm", @"15", @"", nil];

    }

    else

    {

        nice = [[NSArray alloc] initWithObjects:@"17kg", @"17cm", @"16", @"", nil];

    }

    

    [self.tableView reloadData];

    

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }

    

    // Configure the cell...

    cell.textLabel.text = [nice objectAtIndex:[indexPath row]];

    

    return cell;

}



#pragma mark - Table view delegate


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    

}

@end



테이블뷰를 이용한 이동 관련 소스