在viewDidLoad
我有下列方式實現了自定義背景UINavigationBar的:奇怪的行爲被按下
[self.navigationController.navigationBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:nav_bg_image]] atIndex:100];
在堆棧的頂部(稱之爲RVC
)我有以下完整的代碼:
UIImageView *logoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:navbar_image_logo]];
[self.navigationController.navigationBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:nav_bg_image]] atIndex:100];
[self.navigationItem setTitleView:logoView];
[logoView release];
這工作出色。然而,當我在堆棧上推送新VC
和viewDidLoad
UIImageView *logoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:navbar_image_logo]];
[self.navigationController.navigationBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:nav_bg_image]] atIndex:1];
[self.navigationItem setTitleView:logoView];
[logoView release];
UIBarButtonItem *hButton = [[UIBarButtonItem alloc] initWithTitle:@"Filters" style:UIBarButtonItemStylePlain target:self action:@selector(filtersAction)];
self.navigationItem.rightBarButtonItem = hButton;
[hButton release];
使用相同的代碼出現無論是「過濾器」按鈕,也沒有titleview的ImageView的。但是,我知道過濾器按鈕已添加到用戶界面,因爲如果我點擊它應該出現的區域,則會執行操作。
此外,當我深入查看詳細視圖DVC
並返回時,突然出現titleView(logoView)!
我懷疑這是某種內存問題,但我一直無法解決它。
感謝您提供非常豐富的答案! –