10

ShareKit では、モーダル ビューを表示できるように、コードで rootViewController の場所を特定する必要があります。何らかの理由で、iOS 5 でコードが失敗しています。

    // Try to find the root view controller programmically

    // Find the top window (that is not an alert view or other window)
    UIWindow *topWindow = [[UIApplication sharedApplication] keyWindow];
    if (topWindow.windowLevel != UIWindowLevelNormal)
    {
        NSArray *windows = [[UIApplication sharedApplication] windows];
        for(topWindow in windows)
        {
            if (topWindow.windowLevel == UIWindowLevelNormal)
                break;
        }
    }

    UIView *rootView = [[topWindow subviews] objectAtIndex:0];  
    id nextResponder = [rootView nextResponder];

    if ([nextResponder isKindOfClass:[UIViewController class]])
        self.rootViewController = nextResponder;

    else
        NSAssert(NO, @"ShareKit: Could not find a root view controller.  You can assign one manually by calling [[SHK currentHelper] setRootViewController:YOURROOTVIEWCONTROLLER].");

これはアサートを打っています。

代わりに、単に次のコードを使用することの何が問題になっていますか?

rootViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController];

これはうまく機能しているようです。条件によっては失敗する?

4

3 に答える 3

28

window.rootViewControllerb/cに依存できるかどうかはわかりません。設定する必要はありません。ウィンドウにサブビューを追加するだけです。以下はうまくいくように見えました:

id rootVC = [[[[[UIApplication sharedApplication] keyWindow] subviews] objectAtIndex:0] nextResponder];
于 2011-12-21T07:17:38.233 に答える