以前に単純なココア タッチ アプリを作成したことがありますが、UINavigationControllers を使用したことはありません。アドバイスをいただければ幸いです。
店舗名のリストの配列を UITableView に追加しようとしています。UITableView は、タブ バーのタブから UINavigation コントローラーを介してアクセスされます。
タブバーを保持する TabBarController.xib ファイルがあります。UINavigationController を保持する AtoZNavigationController.xib もあります。そして、UITableView を保持する AtoZTableController.xib ファイルがあります。
これは私の AppDelegate.h です:
#import <UIKit/UIKit.h>
@class AtoZNavigationController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) IBOutlet UITabBarController *rootController;
@property (strong, nonatomic) IBOutlet AtoZNavigationController *navController;
@end
AppDelegate.m
#import "AppDelegate.h"
#import "AtoZNavigationController.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize rootController;
@synthesize navController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
[[NSBundle mainBundle] loadNibNamed:@"TabBarController" owner:self options:nil];
[self.window addSubview:rootController.view];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
@end
AtoZNavigationController.h
#import <UIKit/UIKit.h>
@interface AtoZNavigationController : UINavigationController
@end
AtoZNavigationController.m
#import "AtoZNavigationController.h"
@interface AtoZNavigationController ()
@end
@implementation AtoZNavigationController
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
-(void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
AtoZTableController.h
#import <UIKit/UIKit.h>
@interface AtoZTableController : UITableViewController <UITableViewDelegate, UITableViewDataSource>
{
IBOutlet UITableView *AtoZTableView;
NSMutableArray *AtoZArray;
}
@property (nonatomic, retain) IBOutlet UITableView *AtoZTableView;
@end
AtoZTableController.h
#import "AtoZTableController.h"
@interface AtoZTableController ()
@end
@implementation AtoZTableController
@synthesize AtoZTableView;
-(id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
-(void)viewDidLoad
{
[super viewDidLoad];
self.title = NSLocalizedString(@"A to Z", @"An A to Z List of Stores");
AtoZArray = [[NSMutableArray alloc] init];
[AtoZArray addObject:@"Apple"];
[AtoZArray addObject:@"Boots"];
[AtoZArray addObject:@"Topman"];
}
-(void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 0;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [AtoZArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
NSInteger row = [indexPath row];
cell.textLabel.text = [AtoZArray objectAtIndex:row];
return cell;
}
#pragma mark - Table view delegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
}
@end