2011年12月6日火曜日

[ios][storyboard]ストリーボードの動作を確認してみた


まず、よくストリーボードでviewControllerからviewControllerをつなぐsegueをモーダルで画面遷移を定義していくが、AからBへいってBからAに戻る遷移をモーダルでつなぐ人がいたので、それはさすがに違うだろうと思うので実際確認してみた。

- (void)viewDidAppear:(BOOL)animated
{
    NSLog(@"%@",self);
    [super viewDidAppear:animated];
}


2011-12-06 00:26:53.328 modaltest[25564:f803]
2011-12-06 00:26:56.094 modaltest[25564:f803]
2011-12-06 00:27:04.040 modaltest[25564:f803]
2011-12-06 00:27:05.722 modaltest[25564:f803]
2011-12-06 00:27:09.271 modaltest[25564:f803]
2011-12-06 00:27:11.272 modaltest[25564:f803]

当たり前だけど、違うメモリアドレスを返してくる。やはり、モダールはちゃんと
dismissは自分で実装しないといけないみたい。
メモリは同じなので、遷移のスタックがたまっていってるのかな。


資料を探して行き詰まっていたけど、なんだかんだでたよりになるのは
テンプレートのソース。

リストテンプレートを見ればsegueからデータを次のviewControllerに渡す方法も分かる。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

    if ([[segue identifierisEqualToString:@"showDetail"]) {

        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        NSManagedObject *selectedObject = [[self fetchedResultsControllerobjectAtIndexPath:indexPath];
        [[segue destinationViewControllersetDetailItem:selectedObject];
    }
}


リストテンプレートにCoreDataをチェックして作れば、動的Propetyでの利用の仕方が分かる。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];    return cell;
}
カスタムセルが作りやすくなっている気がします。

意外と使えるかも、ストリーボード!