سؤال

I'm using this custom component for hashtag detection in my app. I have added STTweetLabel's as subviews to my custom table view cells. However, clicking on any hashtag invokes the STTweetLabel handler block AND also calls the tableview's didSelectRowAtIndexPath delegate which results in a push to another controller. How do I disable this from happening? i.e. prevent the didSelectRowAtIndexPath behaviour on the STTweetLabels?

Code:
[hashtagLabel setDetectionBlock:^(STTweetHotWord hotWord, NSString *string, NSString *protocol, NSRange range) {
            // call delegate to respond to hashtag selection
        }];
هل كانت مفيدة؟

المحلول

Try to delete

[super touchesBegan:touches withEvent:event];
[super touchesMoved:touches withEvent:event];
[super touchesEnded:touches withEvent:event];

in STTweetLabel.m

I use TTTAttributedLabel now, you can also try it.

نصائح أخرى

If your problem is cell highlight then use this.

cell.selectionStyle = UITableViewCellSelectionStyleNone;

Or use this for prevent invoke didSelectRowAtIndexPath.

tableView:willSelectRowAtIndexPath:

I hope it will help you

You can either prevent the cell from being selected at all in the interface builder or in code using the UITableViewCellSelectionStyleNone selection style.

or in your -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath method return nil for the indexPath of the cells you don't want to get selected

Actually didSelectRowAtIndexPath method always get called first and this solution may work if your label will not cover whole your cell.

If you are doing some task in didSelectRowAtIndexPath then do this steps

1> cell.selectionStyle = UITableViewCellSelectionStyleNone;

2> make custom cell put button back side of label .On button put uilabel then you can add action on that button and do some task when button tapped and as well you can detect label tap seperately

the dirty way:

put your STTweetLabel inside an UIButton without target and action

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top