問題描述:假如A頁面的標題非常長,從A頁面push到B頁面的時候,B頁面的標題會向右偏移,不能居中顯示。
原因是: B頁面的back文字太長了,而B頁面的back文字其實就是A頁面的標題,說白了就是A頁面的標題太長了,導致B頁面的標題不能居中顯示。
解決辦法:在A頁面的viewWillDisappear中設置如下代碼:
A和都是UIViewController時:
// 1.把返回文字的標題設置為空字符串(A和B都是UIViewController)
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
A屬于UITabBarController,B是UIViewController 時:
// 2.A屬于UITabBarController,B是UIViewController
self.tabBarController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];