- 今天剛接觸到自定義tabBar缸沃,當自己定義完tabBar之后在loadView把原來的tabBar上的button移除的時候發(fā)現(xiàn)怎么也不行,后來經(jīng)提醒要在viewWillappear這個方法里寫才行
![打印結果.png](http://upload-images.jianshu.io/upload_images/1511652-8da3100aef497080.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
-(void)viewWillAppear:(BOOL)animated
{
// [super viewWillAppear:animated];
NSLog(@"移除之前個數(shù)-----%zd",self.tabBar.subviews.count);
// 移除tabBar之前的按鈕
for (UIView *childView in self.tabBar.subviews) {
if (![childView isKindOfClass:[ZSTabBar class]]) {
[childView removeFromSuperview];
}
}
NSLog(@"移除之后個數(shù)----%zd",self.tabBar.subviews.count);
}
打印結果.png
tabBar.png
- 當時第一時間就知道這個打印結果不對,不可能是1個拆融,但是也不知道錯在了哪里勾缭,然后蠢蠢的自己弄了好久才發(fā)現(xiàn)在調用viewWillappear的時候忘了調用父類的方法來還原本來的一些操作.加上這句就好了
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(@"移除之前個數(shù)-----%zd",self.tabBar.subviews.count);
// 移除tabBar之前的按鈕
for (UIView *childView in self.tabBar.subviews) {
if (![childView isKindOfClass:[ZSTabBar class]]) {
[childView removeFromSuperview];
}
}
NSLog(@"移除之后個數(shù)----%zd",self.tabBar.subviews.count);
}
- 然后一切都正常了,啦啦啦,看來是系統(tǒng)的tabBar的按鈕會在這個方法里面才加進去
改完之后.png
改完之后tabBar.png