Two Tabbar workarounds for iOS custom Tabbar after Poptorootviewcontriller and Poptoviewcontroller

Source: Internet
Author: User
Tags uicontrol

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.