23

ストーリーボードの前は、アウトレットをクラスにドラッグするだけでデリゲートとデータソースを設定できました。ストーリーボードでは、アウトレットを別のViewControllerにドラッグできません。それに応答する宛先はありません。

ビューコントローラオブジェクトをクリックすると、下部にクラスの所有者が表示されますが、コンセントを含む他のビューコントローラを選択するとすぐに古い選択が失われるため、2つを接続できません。

これは、プログラムでのみ接続する必要があるというAppleの言い方ですか?

4

2 に答える 2

29

正しい。メソッドにデリゲートまたはその他のデータを設定しますprepareForSegue:sender:。次に例を示します。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Check the segue identifier
    if ([segue.identifier isEqualToString:@"showDetail"])
    {
        // Get a reference to your custom view controller
        CustomViewController *customViewController = segue.destinationViewController;

        // Set your custom view controller's delegate
        customViewController.delegate = self;
    }
}
于 2012-01-25T14:44:23.317 に答える
0

ストーリーボードのセグエの宛先であるViewControllerがUIViewControllerの場合、@Marcoの答えは正しいです。ただし、宛先のView ControllerがUINavigationViewControllerの場合は、UINavigationViewControllerからUIViewControllerを取得する必要があります。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Check the segue identifier
    if ([segue.identifier isEqualToString:@"chooseCategoryType"])
    {
        // Get a reference of your custom view controller if your segue connection is an UIViewController
        // CustomViewController *customViewController = segue.destinationViewController;
        // Get a reference of your custom view controller from navigation view controller if your segue connection is an UINavigationViewController
        CustomViewController *customViewController = [[[segue destinationViewController] viewControllers] objectAtIndex:0];

        // Set your custom view controller's delegate
        customViewController.delegate = self;
    }
}
于 2016-08-24T08:08:53.780 に答える