IOS UILabel用UITapGestureRecognizer实现点击事件
2015-12-22 09:35 一树一菩提 阅读(3052) 评论(0) 编辑 收藏 举报点击UILabel跳转页面:
//定义UILabel
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
用UITapGestureRecognizer手势触碰实现UILabel的点击事件
UITapGestureRecognizer *tapName = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchHeaderImageView:)];
self.nameLabel.userInteractionEnabled = YES;
[self.nameLabel addGestureRecognizer:tapName];
- (void)touchHeaderImageView:(UITapGestureRecognizer *)gesture
{
if (self.delegate && [self.delegate respondsToSelector:@selector(touchPersonalMoment:)])
{
[self.delegate touchPersonalMoment: self.commentTable.createUserId];
}
}
- (void)touchPersonalMoment:(NSString *)friendId
{
FriendDetailViewController *viewController = [[FriendDetailViewController alloc] initWithNibName:@"FriendDetailViewController" bundle: nil];
viewController.hidesBottomBarWhenPushed = YES;
viewController.friendId = friendId;
[self.navigationController pushViewController: viewController animated: YES];
}