私は非常に単純なゼロ構成カテゴリを作成して、アプリ全体ですべての戻るボタンのタイトルを非表示にしました。ここで確認できます。この質問はすでに回答を受け入れていますが、他の人にとっては役立つかもしれません。
編集:
.hファイル
#import <UIKit/UIKit.h>
@interface UINavigationController (HideBackTitle)
extern void PJSwizzleMethod(Class cls, SEL originalSelector, SEL swizzledSelector);
@end
.mファイル
#import "UINavigationController+HideBackTitle.h"
#import <objc/runtime.h>
@implementation UINavigationController (HideBackTitle)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
PJSwizzleMethod([self class],
@selector(pushViewController:animated:),
@selector(pj_pushViewController:animated:));
});
}
- (void)pj_pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
UIViewController *disappearingViewController = self.viewControllers.lastObject;
if (disappearingViewController) {
disappearingViewController.navigationItem.backBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
}
if (!disappearingViewController) {
return [self pj_pushViewController:viewController animated:animated];
}
return [self pj_pushViewController:viewController animated:animated];
}
@end
void PJSwizzleMethod(Class cls, SEL originalSelector, SEL swizzledSelector)
{
Method originalMethod = class_getInstanceMethod(cls, originalSelector);
Method swizzledMethod = class_getInstanceMethod(cls, swizzledSelector);
BOOL didAddMethod =
class_addMethod(cls,
originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(cls,
swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
}