10

を提示すると、次のクラッシュが発生しますMFMailComposeViewController

2013-11-08 11:04:05.963 <redacted>[7108:1603] *** Assertion failure in NSDictionary *_UIRecordArgumentOfInvocationAtIndex(NSInvocation *, NSUInteger, BOOL)(), /SourceCache/UIKit/UIKit-2380.17/UIAppearance.m:1118
2013-11-08 11:04:06.032 <redacted>[7108:1603] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unknown key, "NSColor" in title text attributes dictionary'

AppDelegate のapplication:didFinishLaunchingWithOptions:メソッドで次の外観設定まで追跡しました。

        [[UINavigationBar appearance] setTitleTextAttributes:
            @{NSForegroundColorAttributeName : [UIColor whiteColor]}];

その行をコメントアウトするとうまくいきますが、アプリの残りの部分が台無しになるため、titleTextAttributes を空の辞書に具体的に設定してみましたMFMailComposeViewController

試み #1

        [[UINavigationBar appearanceWhenContainedIn:
            NSClassFromString(@"MFMailComposeViewController"), nil]
            setTitleTextAttributes:@{ }];

その結果、同じクラッシュが発生します。と

        [[UINavigationBar appearanceWhenContainedIn:
            NSClassFromString(@"MFMailComposeViewController"), nil]
            setTitleTextAttributes:nil];

また、同じクラッシュが発生します。

試み #2

であることに気付いたMFMailComposeViewControllerのでUINavigationController、グローバルな外観設定が UINavigationControllerの UIViewControllers にローカライズされている可能性があります。MFMailComposeViewController 内にあるビュー コントローラーを特定するコードをいくつかまとめました。

        for (UIViewController *viewController in mailViewController.viewControllers) {
            NSLog(@"%@", NSStringFromClass([viewController class]));
        }

出力は次のようになります。

2013-11-08 11:04:05.936 <redacted>[7108:907] MFMailComposeInternalViewController

だから私は試しました(Appleのプライベートビューコントローラーに頼るのは悪い習慣ですが)

        [[UINavigationBar appearanceWhenContainedIn:
            NSClassFromString(@"MFMailComposeViewController"), nil]
            setTitleTextAttributes:@{ }];

        [[UINavigationBar appearanceWhenContainedIn:
            NSClassFromString(@"MFMailComposeViewController"), nil]
            setTitleTextAttributes:nil];

しかし、それでも同じクラッシュが発生します。

試み #3

        // right before instantiating the MFMailComposeViewController
        [[UINavigationBar appearance] setTitleTextAttributes:@{ }];

        [[UINavigationBar appearance] setTitleTextAttributes:nil];

次に、の完了ブロックでグローバルな外観プロパティを復元しますdismissViewController:animated:completion:

しかし、この方法もうまくいきませんでした。UINavigationBarMFMailComposeViewControllerをクラッシュさせずに、グローバルな外観にtitleTextAttributes を設定する方法を知っている人はいますか?

4

3 に答える 3

2

UINavigationController クラスを拡張するだけです

@interface MyNavigationController : UINavigationController
@end

アプリデリゲートのすべての UINavigationController クラスを新しいサブクラスと [appearanceWhenContainedIn:] に置き換えます

[UINavigationBar appearanceWhenContainedIn:[MyNavigationController class], nil].titleTextAttributes = @{ NSForegroundColorAttributeName : [UIColor whiteColor] };

その後、アプリはクラッシュしません。

于 2014-01-15T06:05:24.390 に答える
0

これを解決できた唯一の方法[[UINavigationBar appearanceWhenContainedIn:] setTitleTextAttributes:]は、UIViewControllers. 幸いなことに、これは非常に簡単でした。なぜなら、私のカスタム ビュー コントローラーはすべて 4 つのビュー コントローラー サブクラスに由来するからです。

編集:私はばかなので、この回答を参照してください。

于 2013-11-08T19:38:08.043 に答える