jverkoey / nimbus

The iOS framework that grows only as fast as its documentation
nimbuskit.info
Apache License 2.0
6.45k stars 1.3k forks source link

NIAttributedLabel does not detect quick taps and crashes on long press inside UICollectionViewCell #496

Closed modastic closed 10 years ago

modastic commented 10 years ago

I have a NIAttributedLabel setup in a UICollectionViewCell like so: (with the delegate methods in the right place)

        NIAttributedLabel *label = [[NIAttributedLabel alloc] initWithFrame:CGRectMake(10, 5, 300, 200)];
        [label setNumberOfLines:0];
        [label setLineBreakMode:NSLineBreakByWordWrapping];
        [label setFont:[UIFont systemFontOfSize:16]];
        [label setDelegate:self];
        [label setAutoDetectLinks:YES];
        label.attributesForHighlightedLink = 
               [NSDictionary dictionaryWithObject:(id)RGBCOLOR(255, 0, 0).CGColor 
                forKey:(NSString *)kCTForegroundColorAttributeName];
        [label setText:@"http://www.google.com THIS IS MY LINK"];
        NSRange linkRange = [label.text rangeOfString:@"LINK"];
        [label addLink:[NSURL URLWithString:@"www.github.com"] range:linkRange];
        [self addSubview:label];

When tapping on the links, the delegate does not get called. When long pressing on the links, the app crashes with this error.

*\ Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSConcreteMutableAttributedString addAttribute:value:range:: nil value'

Now if I move the exact code out of the UICollectionView and into a normal UIView, everything works perfectly. Can anyone tell me what is going on here? Is NIAttributedLabel not compatible with UICollectionViews?

jverkoey commented 10 years ago

This may have been fixed by 979b0e2f24e2a6bc1c4d26e4e671e5bb5670f060. Closing, but please reopen if you're still encountering this problem.