Skip to content

Commit f53b3de

Browse files
committed
任务、讨论 -- 里面的链接支持点击
1 parent 174f56d commit f53b3de

6 files changed

Lines changed: 55 additions & 6 deletions

File tree

Coding_iOS/Controllers/EditTaskViewController.m

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
#import "TaskDescriptionCell.h"
2121
#import "ActionSheetDatePicker.h"
2222
#import "TaskDescriptionViewController.h"
23+
#import "WebViewController.h"
2324

24-
@interface EditTaskViewController ()
25+
@interface EditTaskViewController ()<TTTAttributedLabelDelegate>
2526
@property (strong, nonatomic) UITableView *myTableView;
2627

2728
//评论
@@ -379,6 +380,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
379380
cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_TaskComment forIndexPath:indexPath];
380381
}
381382
cell.curComment = curComment;
383+
cell.contentLabel.delegate = self;
382384
cell.backgroundColor = kColorTableBG;
383385
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:20];
384386
return cell;
@@ -557,6 +559,24 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
557559
}
558560
}
559561

562+
#pragma mark TTTAttributedLabelDelegate
563+
- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithTransitInformation:(NSDictionary *)components{
564+
DebugLog(@"%@", components.description);
565+
HtmlMediaItem *clickedItem = [components objectForKey:@"value"];
566+
[self analyseLinkStr:clickedItem.href];
567+
}
568+
569+
- (void)analyseLinkStr:(NSString *)linkStr{
570+
UIViewController *vc = [BaseViewController analyseVCFromLinkStr:linkStr];
571+
if (vc) {
572+
[self.navigationController pushViewController:vc animated:YES];
573+
}else{
574+
//跳转去网页
575+
WebViewController *webVc = [WebViewController webVCWithUrlStr:linkStr];
576+
[self.navigationController pushViewController:webVc animated:YES];
577+
}
578+
}
579+
560580
- (void)dealloc
561581
{
562582
_myTableView.delegate = nil;

Coding_iOS/Controllers/TopicDetailViewController.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#import "WebViewController.h"
2323
#import "EditTopicViewController.h"
2424

25-
@interface TopicDetailViewController ()
25+
@interface TopicDetailViewController ()<TTTAttributedLabelDelegate>
2626
@property (strong, nonatomic) UITableView *myTableView;
2727
@property (nonatomic, strong) ODRefreshControl *refreshControl;
2828

@@ -258,6 +258,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
258258

259259
TopicCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:toComment.htmlMedia.imageItems.count > 0? kCellIdentifier_TopicComment_Media: kCellIdentifier_TopicComment forIndexPath:indexPath];
260260
cell.toComment = toComment;
261+
cell.contentLabel.delegate = self;
261262
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:45];
262263
return cell;
263264
}
@@ -378,6 +379,13 @@ - (void)analyseLinkStr:(NSString *)linkStr{
378379
}
379380
}
380381

382+
#pragma mark TTTAttributedLabelDelegate
383+
- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithTransitInformation:(NSDictionary *)components{
384+
DebugLog(@"%@", components.description);
385+
HtmlMediaItem *clickedItem = [components objectForKey:@"value"];
386+
[self analyseLinkStr:clickedItem.href];
387+
}
388+
381389
- (void)dealloc
382390
{
383391
_myTableView.delegate = nil;

Coding_iOS/Views/Cell/TaskCommentCell.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
@interface TaskCommentCell : UITableViewCell
1616
@property (strong, nonatomic) TaskComment *curComment;
17+
@property (strong, nonatomic) UITTTAttributedLabel *contentLabel;
18+
1719
+ (CGFloat)cellHeightWithObj:(id)obj;
1820

1921
@end

Coding_iOS/Views/Cell/TaskCommentCell.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
@interface TaskCommentCell ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
2121
@property (strong, nonatomic) UIImageView *ownerIconView;
22-
@property (strong, nonatomic) UILabel *contentLabel, *timeLabel;
22+
@property (strong, nonatomic) UILabel *timeLabel;
2323
@property (strong, nonatomic) UICustomCollectionView *imageCollectionView;
2424

2525
@end
@@ -38,9 +38,11 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
3838
[self.contentView addSubview:_ownerIconView];
3939
}
4040
if (!_contentLabel) {
41-
_contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(kTaskCommentCell_LeftContentPading, curBottomY, kTaskCommentCell_ContentWidth, 30)];
41+
_contentLabel = [[UITTTAttributedLabel alloc] initWithFrame:CGRectMake(kTaskCommentCell_LeftContentPading, curBottomY, kTaskCommentCell_ContentWidth, 30)];
4242
_contentLabel.textColor = [UIColor colorWithHexString:@"0x555555"];
4343
_contentLabel.font = kTaskCommentCell_FontContent;
44+
_contentLabel.linkAttributes = kLinkAttributes;
45+
_contentLabel.activeLinkAttributes = kLinkAttributesActive;
4446
[self.contentView addSubview:_contentLabel];
4547
}
4648
if (!_timeLabel) {
@@ -75,6 +77,13 @@ - (void)setCurComment:(TaskComment *)curComment{
7577
[_ownerIconView sd_setImageWithURL:[_curComment.owner.avatar urlImageWithCodePathResizeToView:_ownerIconView] placeholderImage:kPlaceholderMonkeyRoundView(_ownerIconView)];
7678
NSString *contentStr = _curComment.content;
7779
[_contentLabel setLongString:contentStr withFitWidth:kTaskCommentCell_ContentWidth];
80+
81+
for (HtmlMediaItem *item in _curComment.htmlMedia.mediaItems) {
82+
if (item.displayStr.length > 0 && !(item.type == HtmlMediaItemType_Code ||item.type == HtmlMediaItemType_EmotionEmoji)) {
83+
[_contentLabel addLinkToTransitInformation:[NSDictionary dictionaryWithObject:item forKey:@"value"] withRange:item.range];
84+
}
85+
}
86+
7887
curBottomY += [contentStr getHeightWithFont:kTaskCommentCell_FontContent constrainedToSize:CGSizeMake(kTaskCommentCell_ContentWidth, CGFLOAT_MAX)] + 5;
7988

8089
NSInteger imagesCount = _curComment.htmlMedia.imageItems.count;

Coding_iOS/Views/Cell/TopicCommentCell.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
@interface TopicCommentCell : UITableViewCell
1616
@property (strong, nonatomic) ProjectTopic *toComment;
17+
@property (strong, nonatomic) UITTTAttributedLabel *contentLabel;
1718

1819
+ (CGFloat)cellHeightWithObj:(id)obj;
1920

Coding_iOS/Views/Cell/TopicCommentCell.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
@interface TopicCommentCell ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
1919
@property (strong, nonatomic) UIImageView *ownerIconView;
20-
@property (strong, nonatomic) UILabel *contentLabel, *timeLabel;
20+
@property (strong, nonatomic) UILabel *timeLabel;
2121
@property (strong, nonatomic) UICustomCollectionView *imageCollectionView;
2222
@end
2323

@@ -37,9 +37,11 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
3737
}
3838
CGFloat curWidth = kScreen_Width - 40 - 2*kPaddingLeftWidth;
3939
if (!_contentLabel) {
40-
_contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(kPaddingLeftWidth + 40, curBottomY, curWidth, 30)];
40+
_contentLabel = [[UITTTAttributedLabel alloc] initWithFrame:CGRectMake(kPaddingLeftWidth + 40, curBottomY, curWidth, 30)];
4141
_contentLabel.textColor = [UIColor colorWithHexString:@"0x555555"];
4242
_contentLabel.font = kTopicCommentCell_FontContent;
43+
_contentLabel.linkAttributes = kLinkAttributes;
44+
_contentLabel.activeLinkAttributes = kLinkAttributesActive;
4345
[self.contentView addSubview:_contentLabel];
4446
}
4547
CGFloat commentBtnWidth = 40;
@@ -76,6 +78,13 @@ - (void)setToComment:(ProjectTopic *)toComment{
7678
CGFloat curWidth = kScreen_Width - 40 - 2*kPaddingLeftWidth;
7779
[_ownerIconView sd_setImageWithURL:[_toComment.owner.avatar urlImageWithCodePathResizeToView:_ownerIconView] placeholderImage:kPlaceholderMonkeyRoundView(_ownerIconView)];
7880
[_contentLabel setLongString:_toComment.content withFitWidth:curWidth];
81+
82+
for (HtmlMediaItem *item in _toComment.htmlMedia.mediaItems) {
83+
if (item.displayStr.length > 0 && !(item.type == HtmlMediaItemType_Code ||item.type == HtmlMediaItemType_EmotionEmoji)) {
84+
[_contentLabel addLinkToTransitInformation:[NSDictionary dictionaryWithObject:item forKey:@"value"] withRange:item.range];
85+
}
86+
}
87+
7988
curBottomY += [_toComment.content getHeightWithFont:kTopicCommentCell_FontContent constrainedToSize:CGSizeMake(curWidth, CGFLOAT_MAX)] + 5;
8089

8190
NSInteger imagesCount = _toComment.htmlMedia.imageItems.count;

0 commit comments

Comments
 (0)