どのように再利用できるかについては少し混乱していますuitableviewcell
。
だからここに私のオリジナルコードがあります:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ProductsViewCell";
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell =
[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIWebView* webView = [[UISynchedWebView alloc] initWithFrame:
CGRectMake(0,0, 320, 44)];
webView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
webView.tag = 1001;
webView.userInteractionEnabled = NO;
webView.opaque = NO;
webView.backgroundColor = [UIColor clearColor];
[cell addSubview:webView];
}
UIWebView* webView = (UIWebView*)[cell viewWithTag:1001];
UIFont *font = [UIFont fontWithName:@"Arial" size:15.0f];
NSString *html =
[NSString stringWithFormat:
@"<html>\n"
"<head>\n"
"</head>\n"
"<body><div style=\"padding:5px 0px; text-align:center\"><b>test</b></div></body>\n"
"</html>"];
[webView loadHTMLString:html
baseURL:nil];
return cell;
}
以下のようなif条件があります。
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ProductsViewCell";
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell =
[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIWebView* webView = [[UISynchedWebView alloc] initWithFrame:
CGRectMake(0,0, 320, 44)];
webView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
webView.tag = 1001;
webView.userInteractionEnabled = NO;
webView.opaque = NO;
webView.backgroundColor = [UIColor clearColor];
[cell addSubview:webView];
}
//some process here to get isHTML...
if (isHTML) {
UIWebView* webView = (UIWebView*)[cell viewWithTag:1001];
UIFont *font = [UIFont fontWithName:@"Arial" size:15.0f];
NSString *html =
[NSString stringWithFormat:
@"<html>\n"
"<head>\n"
"</head>\n"
"<body><div style=\"padding:5px 0px; text-align:center\"><b>test</b></div></body>\n"
"</html>"];
[webView loadHTMLString:html
baseURL:nil];
}
else{
cell.textLabel.text = @"Not HTML";
}
return cell;
}
私のコンテンツは動的であるため、コンテンツが であるwebview
場合のみhtml
をロードしたいのですが、それ以外の場合は通常のテキストとしてロードし、cell UILabel
上記の if 条件を使用してwebview
、 cell との重複を取得しUILabel
ます。どうすれば達成できますか?