Two Tabbar workarounds for iOS custom Tabbar after Poptorootviewcontriller and Poptoviewcontroller
Issue: Two Tabbar on iOS custom tabbar after Poptorootviewcontriller and Poptoviewcontroller
1. Custom code:
-(void) Viewwillappear: (BOOL) animated
{
[Super viewwillappear:animated];
Delete System auto-generated Uitabbarbutton
[Self Removetabbarbutton];
}
-(void) Removetabbarbutton {
Delete System auto-generated Uitabbarbutton
For (UIView *child in self.tabBar.subviews) {
if ([Child Iskindofclass:[uicontrol class]]) {
[Child Removefromsuperview];
}
}
}
/**
* Initialize Tabbar
*/
-(void) Setuptabbar
{
Hyttabbar *customtabbar = [[Hyttabbar alloc] init];
Customtabbar.frame = Self.tabBar.bounds;
Customtabbar.delegate = self;
[Self.tabbar Addsubview:customtabbar];
Self.customtabbar = Customtabbar;
}
2.pop Code:
[Self.navigationcontroller poptoviewcontroller:strongself.navigationcontroller.childviewcontrollers[1] Animated: YES];
3. Results:
Workaround:
1. Notify when pop is sent (note that the VC controller that is going to pop back with Tabber)
Nsnotification *notification =[nsnotification notificationwithname:@ "Hytpopviewcontrollernotification" Object:nil Userinfo:nil];
[[Nsnotificationcenter Defaultcenter] postnotification:notification];
2. Register the notification in the Viewdidload method of the custom Tabcontroller, call the Removetabbarbutton method to remove the system that comes with it.
-(void) Viewdidload {
[Super Viewdidload];
Initialize Tabbar
[Self setuptabbar];
//.../
[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (hytpopviewcontrollernotification) name:@ "Hytpopviewcontrollernotification" Object:nil];
}
-(void) Hytpopviewcontrollernotification {
Delete System auto-generated Uitabbarbutton
For (UIView *child in self.tabBar.subviews) {
if ([Child Iskindofclass:[uicontrol class]]) {
[Child Removefromsuperview];
}
}
}
PS: I tried to call several Popviewcontroller methods in succession to replace Poptoviewcontroller, and the result is normal.
This shows that the implementations of Popviewcontroller and Poptoviewcontroller are at least intrinsically different on custom tabbar.
Two Tabbar workarounds for iOS custom Tabbar after Poptorootviewcontriller and Poptoviewcontroller