前回作成したテーブルビューから遷移する詳細ビューを追加する。
詳細ビューとして、ストーリーボードにView Controller(紐づけるクラス名はDetailViewControllerとする)を追加する。
Table View Controller(クラス名:ViewController)からView Controller(クラス名:DetailViewController)へのセグエを設定する。
Storyboard Segue: 「identifier」に"getDetail"と入力、「Style」に"push"を選択する。
Table View Controller(クラス名:ViewController)のバックボタン表示名を変更する
Navigation Item: 「Back Button」に"プロ野球"と入力する。
詳細ビュー(クラス名:DetailViewController)をコーディングする。
#import <UIKit/UIKit.h> @interface DetailViewController : UIViewController @property (weak, nonatomic) IBOutlet UILabel *detailLabel; @property (strong, nonatomic) NSString *detailItem; @end
#import "DetailViewController.h"
@implementation DetailViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.detailLabel.text = self.detailItem;
NSLog(@"self.detailItem is %@", self.detailItem);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
テーブルビュー(クラス名:ViewController)をコーディングする。
ViewController.mにおいてDetailViewController.hをインポートし、prepareForSegue: sender:メソッドを追加する。
#import "ViewController.h"
#import "DetailViewController.h"
@interface ViewController ()
@end
@implementation ViewController {
@private
NSArray *_leagueKinds;
NSArray *_leagues;
NSArray *_leaguePrefixes;
}
#pragma mark - Navigation
// In a story board-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
if ([[segue identifier] isEqualToString:@"getDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSArray *teams = _leagues[indexPath.section];
NSArray *teamPrefixes = _leaguePrefixes[indexPath.section];
[[segue destinationViewController] setTitle:teams[indexPath.row]];
[[segue destinationViewController] setDetailItem:teamPrefixes[indexPath.row]];
}
}
@end





