开发者

Uiwebview within uitableview

开发者 https://www.devze.com 2023-02-05 00:11 出处:网络
Is it possible to divide uitableview into 3 parts, one of which is uiwebview (so i can display htm开发者_如何学Pythonl string)? The other 2 parts are just regular strings so I can just display as text

Is it possible to divide uitableview into 3 parts, one of which is uiwebview (so i can display htm开发者_如何学Pythonl string)? The other 2 parts are just regular strings so I can just display as text.


It is possible using custom subclasses of UITableViewCell (just split each cell into 3 subcells and insert a UIWebview into one.); however, it probably goes against the Apple HIG.


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

// Configure the cell...

[self addWebViewToTable:(UITableViewCell *)cell];


return cell;

}

- (void)addWebViewToTable:(UITableViewCell *)cell{
NSString* htmlString = @"<html> <body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>";
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(5.0f,1.0f,40.0f,40.0f)];
[webView loadHTMLString:htmlString baseURL:nil];
[[cell contentView] addSubview:webView];
[webView release];      

}

0

精彩评论

暂无评论...
验证码 换一张
取 消