前回の内容をストリーボードも使わずに実現する。ただし、AppDelegateクラスについてはUINavigationControllerをプロパティとして使い、ViewControllerクラスについてはUITableViewControllerを継承する形式で実現してみる。
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navigationController;
@end
#import "AppDelegate.h"
#import "ViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
ViewController *viewController = [[ViewController alloc] init];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
@end
#import <UIKit/UIKit.h>
@interface ViewController : UITableViewController
@end
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *teams = _leagues[indexPath.section];
NSArray *teamPrefixes = _leaguePrefixes[indexPath.section];
DetailViewController *detailViewController = [[DetailViewController alloc] init];
[detailViewController setTitle:teams[indexPath.row]];
[detailViewController setDetailItem:teamPrefixes[indexPath.row]];
[self.navigationController pushViewController:detailViewController animated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
// I don't care orientation this time!
UILabel *detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
detailLabel.textAlignment = NSTextAlignmentCenter;
detailLabel.backgroundColor = [UIColor clearColor];
detailLabel.text = self.detailItem;
[self.view addSubview:detailLabel];
NSLog(@"self.detailItem is %@", self.detailItem);
}
0 件のコメント:
コメントを投稿