CCDropDownMenu
CCDropDownMenu copied to clipboard
CCdropDownMenu add duplicates in drop down menu after few minutes app running?
I'm sorry, could you provide some details or description? I'm not fully understand what you mean.
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.
When the contents of self. dropDownList
are duplicated, what does
NSLog(@"array %@", Array);
log in the console?
Are the contents of Array
still right?
Hi, Yes content of array are just two elements while the dropdownlist showing multiple duplicates.
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 ?
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.
but it works perfect in ManaDropDownMenu only GaiDropDownMenu has problem
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?
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?
Sorry about digging this old thread up, but I am getting the same issue with ManaDropDownMenu. See attached image.
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.
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.
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.
Any news about fixing the issue?
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 ;
}
}