2012年2月23日木曜日

Storyboard上のViewControllerをプログラムで作る方法


UITableViewでCellが選択されたときに次の画面へ遷移するにはdidSelectRowAtIndexPathメソッドをoverrideします。ところが、Xcodeが作るテンプレートのメソッドではStoryboardの設定が使えません。

- (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];
     */
}

instantiateViewControlを使うとStoryboardに置いた画面を作ることができます。

    //@" PDFWebViewController  "はStoryboardで設定した値。
    PDFWebViewController *vCtr = [[self storyboard] instantiateViewControllerWithIdentifier:@"PDFWebViewController"];

itentifierはXcodeのStoryboradに配置したUIViewControllerのプロパティー画面で
設定します。

0 件のコメント: