ermalkaleci / CarbonKit

CarbonKit - iOS Components (Obj-C & Swift)
MIT License
682 stars 164 forks source link

CarbonTabSwipeNavigation - Add the ability to dynamically add and remove tab pages #21

Open joshuaguy opened 9 years ago

joshuaguy commented 9 years ago

I would like to be able to modify the tab page collection at runtime.

armanim commented 9 years ago

+1

shehabic commented 9 years ago

+2 :)

ermalkaleci commented 9 years ago

Why not :+1:

shehabic commented 9 years ago

I think it's already supported not out of the box, but simply:

- (void)resetView {
    tabSwipe = Nil;
}

// Moving the initialization of tabs into separate method
- (void)viewDidLoad {
    [super viewDidLoad];
    [self initTabs];
}

then the next time you want to initialize new tabs you simple call initTabs (add parameters or whatever), I'm not sure if this method has any memory leaks or not, I actually started iOS only 5 days ago, but this worked perfectly fine.

WilliamHua commented 9 years ago

How were you able to reload the tabs? I tried re-assigning a CarbonTabSwipeNavigation to tabSwipe in the example, and all that happened was that there were two tabSwipes on top of each other.

shehabic commented 9 years ago

Just as I typed above, I moved the initialization code to a separate method, then called it again with the new values

WilliamHua commented 9 years ago

This is similar to what you wrote correct? The dispatch_after should reload the view after a 1 second with a new view, but there are two vies after it is executed (you can see the effect most if you use a new array of names)

    NSArray *names = @[@"ONE", @"TWO", @"THREE", @"FOUR", @"FIVE", @"SIX", @"SEVEN", @"EIGHT", @"NINE", @"TEN"];
UIColor *color = self.navigationController.navigationBar.barTintColor;
tabSwipe = [[CarbonTabSwipeNavigation alloc] createWithRootViewController:self tabNames:names tintColor:color delegate:self];
[tabSwipe setIndicatorHeight:2.f]; // default 3.f
[tabSwipe addShadow];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
    tabSwipe = nil;
        tabSwipe = [[CarbonTabSwipeNavigation alloc] createWithRootViewController:self tabNames:names tintColor:color delegate:self];
        [tabSwipe setIndicatorHeight:2.f]; // default 3.f
        [tabSwipe addShadow];
}
ermalkaleci commented 9 years ago

Hello everyone, if you re-init tabSwipe, you will remove all the cached view controllers. This mean all views are going to re-draw. So I don't think this is the right way.

shehabic commented 9 years ago

In my case that's a good use I actually need to recycle all the views as I'm not just adding extra tab I'm changing all the old tabs with their views with news ones, but may be for others it's not a good use case.

P.S. I'm iOSer only since 1 month, may be I'm doing something wrong

ermalkaleci commented 9 years ago

Hey @WilliamHua If you want just to re-init and don't care about view re-draw, you can remove tabSwipe view before re-init Just like this

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        [tabSwipe.view removeFromSuperview];
        tabSwipe = [[CarbonTabSwipeNavigation alloc] createWithRootViewController:self tabNames:names tintColor:color delegate:self];
        [tabSwipe setIndicatorHeight:2.f]; // default 3.f
        [tabSwipe addShadow];
}
qasimmajeed commented 8 years ago

HI @ermalkaleci i am just facing problem with this RightToLeft Layout is this any possibility to fix and enforce the library to use only LeftToRight layout

ermalkaleci commented 8 years ago

Hi @qasimmajeed, I am sorry, I have no experience with RTL and don't know where the problem is.

danartinho commented 8 years ago

Can I add a new tab page without re-init all the existing page?

mairajKhoso commented 5 years ago

screen shot 2018-12-03 at 2 20 39 pm I just want to remove the tabnavigation bar color

Md-Rais commented 4 years ago

Hey @WilliamHua If you want just to re-init and don't care about view re-draw, you can remove tabSwipe view before re-init Just like this

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        [tabSwipe.view removeFromSuperview];
        tabSwipe = [[CarbonTabSwipeNavigation alloc] createWithRootViewController:self tabNames:names tintColor:color delegate:self];
        [tabSwipe setIndicatorHeight:2.f]; // default 3.f
        [tabSwipe addShadow];
}

Dear @ermalkaleci , You have been an awesome guy for making CarbonTabSwipeNavigation and making developer's life easier. I am stuck with one problem in which I wanted to dynamically add the tabs which I am able to add it but before adding the new tabs, I am trying to remove the old cache data by calling this method:-

DispatchQueue.main.async {
     self.carbonTabSwipeNavigation.removeFromParent() 
} 

But the above code doesn't remove the cache data. Shown in the picture below: Simulator Screen Shot - iPhone 11 Pro Max - 2020-07-08 at 14 23 28

Please help us to clear the old data and UI, before re-init new tabs.

Md-Rais commented 4 years ago

Dears,

Instead of the code below:

DispatchQueue.main.async {
      self.carbonTabSwipeNavigation.removeFromParent() 
} 

The old data was removed by the following method successfully, self.carbonTabSwipeNavigation.view.removeFromSuperview()

Cheers