1

Is it possible to divide uitableview into 3 parts, one of which is uiwebview (so i can display html string)? The other 2 parts are just regular strings so I can just display as text.

Dat Nguyen
  • 74
  • 2
  • 11

2 Answers2

2

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.

Jesse Naugher
  • 9,780
  • 1
  • 41
  • 56
1
- (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];      

}

0x8badf00d
  • 6,391
  • 3
  • 35
  • 68
  • Thanks. Is there a way to automatically resize the images in the html code? Currently they are too big to fit within the iphone screen. – Dat Nguyen Jan 17 '11 at 20:19
  • @Dat NGuyen I am not sure if this is right way to do: look at this http://stackoverflow.com/questions/603907/uiimage-resize-then-crop post to resize your image, store image into documents or temp and then use local file as image source !! hope this helps – 0x8badf00d Jan 17 '11 at 23:31