Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

CCdropDownMenu add duplicates in drop down menu after few minutes app running? #2

Open
miskeen110 opened this issue Dec 10, 2016 · 14 comments

Comments

@miskeen110
Copy link

No description provided.

@miskeen110 miskeen110 changed the title CCdropDownMenu add duplicates in drop down m CCdropDownMenu add duplicates in drop down menu after few minutes app running? Dec 10, 2016
@Cokile
Copy link
Owner

Cokile commented Dec 10, 2016

I'm sorry, could you provide some details or description? I'm not fully understand what you mean.

@miskeen110
Copy link
Author

miskeen110 commented Dec 10, 2016

Here is the code in viewDidLoad

self.dropDownList = [[GaiDropDownMenu alloc] initWithFrame:self.dropDownListView.frame title:@"Choose a option"];
NSUInteger size=[[DeviceManager devices] count];
  NSMutableArray *Array= [[NSMutableArray alloc] init];
   
   // Getting Buddy For Drop Down list
   for (int i=0;i<size;i++) {
       BSDevice *d=[[DeviceManager devices] objectAtIndex:i];
       NSLog(@"Name %@",d.Name);
       
       [Array addObject:d.Name];
   }
   
   
   //Drop Down Menu
       NSLog(@"array %@", Array);
       self.dropDownList.delegate = self;
       self.dropDownList.numberOfRows = size;
   
   self.dropDownList.textOfRows = Array;

when i first time open an application, this drop down list works perfect. After few minutes close the application, its elements are duplicated, the drop down list is multiplied with same elements repeated.
For Example First time DDL has two elements.
After five minutes they are 4 and after fifteen minutes they are six and so on.

@Cokile
Copy link
Owner

Cokile commented Dec 10, 2016

When the contents of self. dropDownList are duplicated, what does

NSLog(@"array %@", Array);

log in the console?

Are the contents of Array still right?

@miskeen110
Copy link
Author

Hi,
Yes content of array are just two elements while the dropdownlist showing multiple duplicates.

@Cokile
Copy link
Owner

Cokile commented Dec 10, 2016

How does the duplication be triggered? Just wait a few minutes without doing anything after launching the app? Or terminate the app and relaunch it after few minutes? Or make the app enter background and re-enter foreground after few minutes ?

@miskeen110
Copy link
Author

Duplication triggered after few minutes application launched and in background the duplication occurs when i open up. But when i terminate the app and start app again then there is no duplication.

@miskeen110
Copy link
Author

miskeen110 commented Dec 10, 2016

but it works perfect in ManaDropDownMenu only GaiDropDownMenu has problem

@Cokile
Copy link
Owner

Cokile commented Dec 11, 2016

Well, theoretically, the difference between ManaDropDownMenu and GaiDropDownMenu is the expansion and close animation. It seems a little strange that ManaDropDownMenu can work while GaiDropDownMenu would cause duplication.

Can you provide a sample project?

@Cokile
Copy link
Owner

Cokile commented Dec 11, 2016

Add the code below at the end of viewDidLoad:

[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(log) name:UIApplicationDidBecomeActiveNotification object:nil];

And add the method below in the implementation scope of your view controller:

- (void)log {
    NSLog(@"number of rows: %@\n", self.dropDownList.textOfRows);

    NSUInteger size=[[DeviceManager devices] count];
    NSMutableArray *Array= [[NSMutableArray alloc] init];
    for (int i=0;i<size;i++) {
        BSDevice *d=[[DeviceManager devices] objectAtIndex:i];
        [Array addObject:d.Name];
    }
    NSLog(@"device names: %@", Array)
}

What would the logs be like when the duplication is triggered?

@Pellagius
Copy link

Sorry about digging this old thread up, but I am getting the same issue with ManaDropDownMenu. See attached image.
duplicatingdropdown

This issue only occurs after some time, I have 7 beta testers on it and none of them can determine the steps required to get it to duplicate, it just seems to 'happen'. That is, when the drop dowm expansion control is tapped the menu displays duplicated sometimes only twice, in the case of the image 4 times.

@Pellagius
Copy link

As of iOS 12 beta 8, the bug I have reported above is now reproduce-able 1:1, simply by selecting the drop down switch, with each new press duplicating the menu again and again.

@Pellagius
Copy link

Pellagius commented Aug 30, 2018

SOLUTION:

From above iOS 12 beta 11 produces this bug 1:1.

Upon calling ManaDropDownMenu: animateForExpansion, drawRect() is invoked. The following hunk exists in ManaDropDownMenu: drawRect:

for (int i = 0; i < self.numberOfRows; i++) {

    CCDropDownMenuCell *cell = [[CCDropDownMenuCell alloc] initWithFrame:self.titleView.bounds andFontSize:self.titleLabel.font.pointSize];

    cell.index = i;

    cell.textAligment = NSTextAlignmentLeft;

    cell.activeColor = self.activeColor;

    cell.inactiveColor = self.inactiveColor;

    cell.text = [self.textOfRows objectAtIndex:i];

    cell.image = [UIImage imageNamed:[self.imageNameOfRows objectAtIndex:i]];

    cell.backgroundColor = [self.colorOfRows objectAtIndex:i]!=nil?[self.colorOfRows objectAtIndex:i]:self.titleViewColor;

    [[NSNotificationCenter defaultCenter] postNotificationName:@"cellBackgroundColorChanged" object:cell];
    
    [cell setNeedsDisplay];
    
    [self insertSubview:cell atIndex:0];

    **_[self.listViews addObject:cell];_**
}

This iteration adds to self.listViews, but it now appears necessary to empty the listviews array inside drawRect:

[self.listViews removeAllObjects]; // Put before the above for loop.

prior to this hunk, to prevent the duplication occurring.

@abbt999
Copy link

abbt999 commented Apr 21, 2019

Any news about fixing the issue?

@iRS3
Copy link

iRS3 commented Jun 21, 2019

Any news about fixing the issue?

Fixed this issue

  • (void)drawRect:(CGRect)rect

This above method call more than one time that's why this issue occurred, for solve this : you can simply create one bool flag and create dropdown menu using that flag. For better understanding please check below code.

@interface ManaDropDownMenu () {
CGFloat originalHeight;
NSInteger originalIndex;

BOOL myFlag ;

}

  • (void)drawRect:(CGRect)rect {

    if (myFlag == NO) {

      CGFloat length = CGRectGetHeight(self.bounds);
      originalHeight = length;
      
      self.titleView.frame = self.bounds;
      [self addSubview:self.titleView];
      
      self.titleLabel.frame = CGRectMake(8, 4, CGRectGetWidth(self.bounds)-length-8, length-8);
      self.titleLabel.textAlignment = NSTextAlignmentLeft;
      self.titleLabel.adjustsFontSizeToFitWidth = YES;
      [self.titleView addSubview:self.titleLabel];
      
      self.indicatorView.frame = CGRectInset(CGRectMake(CGRectGetWidth(self.bounds)-length, 0, length, length), length*0.3, length*0.3);
      [self.titleView addSubview:self.indicatorView];
      
      CGRect frame = CGRectMake(CGRectGetWidth(self.bounds)-length-seperatorWidth, 0, seperatorWidth, length);
      self.seperatorLayer.frame = CGRectInset(frame, 0, length/6);
      [self.titleView.layer addSublayer:self.seperatorLayer];
      
      self.borderLayer.frame = CGRectMake(8, length-0.5, CGRectGetWidth(self.bounds)-16, 0.5);
      self.borderLayer.borderWidth = 0;
      [self.titleView.layer addSublayer:self.borderLayer];
              
      for (int i = 0; i < self.numberOfRows; i++) {
          CCDropDownMenuCell *cell = [[CCDropDownMenuCell alloc] initWithFrame:self.titleView.bounds];
          cell.index = i;
          cell.textAligment = NSTextAlignmentLeft;
          cell.activeColor = self.activeColor;
          cell.inactiveColor = self.inactiveColor;
          cell.text = [self.textOfRows objectAtIndex:i];
          cell.image = [UIImage imageNamed:[self.imageNameOfRows objectAtIndex:i]];
          cell.backgroundColor = [self.colorOfRows objectAtIndex:i]!=nil?[self.colorOfRows objectAtIndex:i]:self.titleViewColor;
          [[NSNotificationCenter defaultCenter] postNotificationName:@"cellBackgroundColorChanged" object:cell];
          
          [cell setNeedsDisplay];
          
          [self insertSubview:cell atIndex:0];
          [self.listViews addObject:cell];
      }
      myFlag = YES ;
    

    }

}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants