Custom UitableViewCell의 UIWebView
-
10-07-2019 - |
문제
이것이 좋은 경로인지 확실하지 않습니다. 문제는 텍스트가 html (p tags 등)입니다. 나의 첫 번째 생각은 셀에 uiwebview를 만들고 loadhtmlstring으로 채워진 것이었다. 사실은, 그것은 일종의 작동한다는 것입니다. 그러나 나는 셀이 더 이상 터치를받는 사람이 아니었다.
따라서 코드가 너무 깊어지기 전에 uiwebview를 사용하는 것보다 셀을 채우는 더 좋은 방법이 있습니까? 그것은 해킹처럼 느껴지고, 그것이 작동하더라도 애플이 그것을 없애는 것을 두려워합니다.
// 내 사용자 정의 UitableViewCell 클래스에서 :
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
[self setFrame:frame];
webcell = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,frame.size.width-20,frame.size.height)];
[self.contentView addSubview:webcell];
//bloack the webview from touches
UIView *cover = [[UIView alloc] initWithFrame:webcell.frame];
[self.contentView addSubview:cover];
[cover release];
}
return self;
}
-(void) setLabelData : (feedItem *) feedItem {link = feedItem.link;
NSMutableString *htmlstring = [NSMutableString string];
[htmlstring appendString:@"<html><head><link rel='stylesheet' href='style.css'/></head><body>"];
[htmlstring appendFormat:@"<p>%@</p>",feedItem.title];
[htmlstring appendFormat:@"<p>%@</p>",feedItem.description];
[htmlstring appendString:@"</body></html>"];
[webcell loadHTMLString:htmlstring baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]bundlePath]]];
}
감사해요
해결책
누군가가 반박하지 않는 한, 나는 uitableviewcell의 uiwebview가 좋은 생각이 아니라고 결론을 내 렸습니다. 그럼에도 불구하고, 나는 로컬 htmlstring으로 테스트하지 않았습니다 ...
다른 팁
우리는 셀에서 webviews를 사용하여 약간의 성공을 거두었습니다. 셀이 터치 이벤트를 받기를 원한다면 WebView를 설정해야합니다. userInteractionEnabled
재산이 아닙니다. WebView는 내용을로드하는 데 약간의 시간이 걸리고 준비되기 전에 재사용 될 수 있으므로 각 셀에 대해 다른 재사용 식별기를 사용해야합니다.
테이블에 필요한 수를 알 자마자 WebView-Cells를 정적으로 할당하여 화면을 오프 스크린을 모두로드하여 시작했습니다. 재사용 식별자가 없으므로 셀을 추적하고 어디로 가야하는지를 추적해야합니다.