Comments (2)
When used with Storyboard, M2DSegmentedControl:initWithItems:
is never called. So, the badgeViews
array is nil
. To resolve, we must recall those missing codes (as following):
self.badgeViews = [NSMutableDictionary new];
[self addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
[self setBadgeBackgroundColor:[UIColor redColor]];
[self setBadgeTextColor:[UIColor whiteColor]];
The last two is straight forward as they are public functions. But the first two are tricky because they are private property/method. So, we need to redeclare them as public (Credit: http://jerrymarino.com/2014/01/31/objective-c-private-instance-variable-access.html).
@interface M2DSegmentedControl()
@property (nonatomic, strong) NSMutableDictionary<NSNumber *, M2DSegmentedControlBadgeView *> *badgeViews;
- (void)valueChanged:(id)sender;
@end
// declare a short cut to the `valueChanged:` as this:
- (void)M2DSegmentedControlValueChanged:(id)sender {
[(M2DSegmentedControl *)sender valueChanged:sender];
}
Now, redo the missing initialization and call this function from viewDidLoad
:
- (void)reinitM2DSegmentedControl:(M2DSegmentedControl *)segmentedControl {
segmentedControl.badgeViews = [NSMutableDictionary new];
[segmentedControl addTarget:self action:@selector(M2DSegmentedControlValueChanged:) forControlEvents:UIControlEventValueChanged];
[segmentedControl setBadgeBackgroundColor:[UIColor redColor]];
[segmentedControl setBadgeTextColor:[UIColor whiteColor]];
}
from m2dsegmentedcontrol.
After using it for a while, I found that this library is quite buggy. For example, if I set a badge with nil text (no value), it will be hidden forever. I have to access the badgeView (via the above hack to the supposed private array) to unhidden it before updating the text.
When the viewController is disappears (for example, a navigation controller event), on return, the badges are gone/hidden/invisible. Can't find a way to show them programatically. But user tapping any other tab on the segment control (any except current one), the badges will come back.
from m2dsegmentedcontrol.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from m2dsegmentedcontrol.