@@ -17,7 +17,7 @@ @interface TopicContentCell ()
1717@property (strong , nonatomic ) UIImageView *userIconView;
1818@property (strong , nonatomic ) UILabel *titleLabel, *timeLabel, *commentCountLabel;
1919@property (strong , nonatomic ) UIButton *commentBtn, *deleteBtn;
20- @property (strong , nonatomic ) UIWebView *topicContentView ;
20+ @property (strong , nonatomic ) UIWebView *webContentView ;
2121@property (strong , nonatomic ) UIActivityIndicatorView *activityIndicator;
2222@end
2323@implementation TopicContentCell
@@ -48,15 +48,15 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
4848 [self .contentView addSubview: _timeLabel];
4949 }
5050 curWidth = kScreen_Width - 2 *kPaddingLeftWidth ;
51- if (!self.topicContentView ) {
52- self.topicContentView = [[UIWebView alloc ] initWithFrame: CGRectMake (kPaddingLeftWidth , 0 , curWidth, 1 )];
53- self.topicContentView .delegate = self;
54- self.topicContentView .scrollView .scrollEnabled = NO ;
55- self.topicContentView .scrollView .scrollsToTop = NO ;
56- self.topicContentView .scrollView .bounces = NO ;
57- self.topicContentView .backgroundColor = [UIColor clearColor ];
58- self.topicContentView .opaque = NO ;
59- [self .contentView addSubview: self .topicContentView ];
51+ if (!self.webContentView ) {
52+ self.webContentView = [[UIWebView alloc ] initWithFrame: CGRectMake (kPaddingLeftWidth , 0 , curWidth, 1 )];
53+ self.webContentView .delegate = self;
54+ self.webContentView .scrollView .scrollEnabled = NO ;
55+ self.webContentView .scrollView .scrollsToTop = NO ;
56+ self.webContentView .scrollView .bounces = NO ;
57+ self.webContentView .backgroundColor = [UIColor clearColor ];
58+ self.webContentView .opaque = NO ;
59+ [self .contentView addSubview: self .webContentView ];
6060 }
6161 if (!_activityIndicator) {
6262 _activityIndicator = [[UIActivityIndicatorView alloc ]
@@ -112,11 +112,15 @@ - (void)setCurTopic:(ProjectTopic *)curTopic{
112112 curBottomY += 10 + 20 ;
113113
114114 // 讨论的内容
115- [self .topicContentView setY: curBottomY];
116- [self .topicContentView setHeight: _curTopic.contentHeight];
117- [_activityIndicator startAnimating ];
118- [self .topicContentView loadHTMLString: [WebContentManager topicPatternedWithContent: _curTopic.htmlMedia.contentOrigional] baseURL: nil ];
119- [_activityIndicator setCenter: CGPointMake (kScreen_Width /2 , curBottomY+5 )];
115+ [self .webContentView setY: curBottomY];
116+ [self .webContentView setHeight: _curTopic.contentHeight];
117+
118+ if (!_webContentView.isLoading ) {
119+ [_activityIndicator startAnimating ];
120+ if (_curTopic.htmlMedia .contentOrigional ) {
121+ [self .webContentView loadHTMLString: [WebContentManager markdownPatternedWithContent: _curTopic.htmlMedia.contentOrigional] baseURL: nil ];
122+ }
123+ }
120124
121125 curBottomY += _curTopic.contentHeight +5 ;
122126 [_commentCountLabel setY: curBottomY+2 ];
@@ -160,7 +164,7 @@ - (void)webViewDidStartLoad:(UIWebView *)webView{
160164 [_activityIndicator startAnimating ];
161165}
162166- (void )webViewDidFinishLoad : (UIWebView *)webView {
163- [self refreshtopicContentView ];
167+ [self refreshwebContentView ];
164168 [_activityIndicator stopAnimating ];
165169 CGFloat scrollHeight = webView.scrollView .contentSize .height ;
166170 if (ABS (scrollHeight - _curTopic.contentHeight ) > 5 ) {
@@ -179,13 +183,13 @@ - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
179183 DebugLog (@" %@ " , error.description );
180184}
181185
182- - (void )refreshtopicContentView {
183- if (_topicContentView ) {
186+ - (void )refreshwebContentView {
187+ if (_webContentView ) {
184188 // NSString *js = @"window.onload = function(){ document.body.style.backgroundColor = '#333333';}";
185- // [_topicContentView stringByEvaluatingJavaScriptFromString:js];
189+ // [_webContentView stringByEvaluatingJavaScriptFromString:js];
186190 // 修改服务器页面的meta的值
187- NSString *meta = [NSString stringWithFormat: @" document.getElementsByName(\" viewport\" )[0].content = \" width=%f , initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\" " , CGRectGetWidth (_topicContentView .frame)];
188- [_topicContentView stringByEvaluatingJavaScriptFromString: meta];
191+ NSString *meta = [NSString stringWithFormat: @" document.getElementsByName(\" viewport\" )[0].content = \" width=%f , initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\" " , CGRectGetWidth (_webContentView .frame)];
192+ [_webContentView stringByEvaluatingJavaScriptFromString: meta];
189193 }
190194}
191195#pragma mark Btn M
0 commit comments