CCDropDownMenu icon indicating copy to clipboard operation
CCDropDownMenu copied to clipboard

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

Open miskeen110 opened this issue 8 years ago • 14 comments

miskeen110 avatar Dec 10 '16 12:12 miskeen110

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

Cokile avatar Dec 10 '16 12:12 Cokile

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.

miskeen110 avatar Dec 10 '16 13:12 miskeen110

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

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

log in the console?

Are the contents of Array still right?

Cokile avatar Dec 10 '16 13:12 Cokile

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

miskeen110 avatar Dec 10 '16 13:12 miskeen110

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 ?

Cokile avatar Dec 10 '16 13:12 Cokile

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 avatar Dec 10 '16 13:12 miskeen110

but it works perfect in ManaDropDownMenu only GaiDropDownMenu has problem

miskeen110 avatar Dec 10 '16 16:12 miskeen110

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 avatar Dec 11 '16 02:12 Cokile

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?

Cokile avatar Dec 11 '16 03:12 Cokile

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 avatar Jul 17 '18 23:07 Pellagius

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 avatar Aug 17 '18 01:08 Pellagius

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.

Pellagius avatar Aug 30 '18 03:08 Pellagius

Any news about fixing the issue?

abbt999 avatar Apr 21 '19 17:04 abbt999

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 ;
    

    }

}

iRS3 avatar Jun 21 '19 10:06 iRS3