2012-05-22 5 views
1

Ну, в основном, я пытаюсь передать строку в uiwebview, что просто так происходит в формате html, однако я передаю его в uiwebview, используя loadHTMLString: myHTML.Создайте richtext uitableviewcell с uiwebview

проблема, с которой я столкнулась, заключается в том, что я вообще не вижу никакого текста. Я настроил пользовательский вид, который затем удалил, добавил uitableviewcell, а затем в ячейку я добавил uiwebview. Затем я установил связанный класс в класс, в котором я хотел бы отобразить tableviewcell, а затем связал свой getter/setter с tableviewcell и uiwebview внутри tableviewcell.

Тогда это код, который следует за мной пытаясь установить богатый текст uiwebview.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (indexPath.section == 0) { 
     if (indexPath.row == 0) { 


      // Set cell height 
      [self tableView:tableView heightForRowAtIndexPath:indexPath]; 

      // Configure the cell using custom cell 
      [[NSBundle mainBundle] loadNibNamed:@"SearchCellHtml" owner:self options:nil]; 
      cell = searchCellHtml; 

      // pass in some data into myHTML 
      myUIWebView = [[UIWebView alloc] init]; 

      NSString *myHTML = @"<html><body><h1>Hello, world!</h1></body></html>"; 
      [myUIWebView loadHTMLString:myHTML baseURL:nil]; 

      //Disclosure Indicator 
      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
     } 

всякая помощь с этим была бы весьма признательна.

ответ

2
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (indexPath.section == 0) { 
     if (indexPath.row == 0) { 

      [self tableView:tableView heightForRowAtIndexPath:indexPath]; 

      // load the cell ? 
      cell = [[NSBundle mainBundle] loadNibNamed:@"SearchCellHtml" owner:self options:nil]; 

      myUIWebView = [[[UIWebView alloc] init] autorelease]; // autorelease 


      NSString *myHTML = @"<html><body><h1>Hello, world!</h1></body></html>"; 
      [myUIWebView loadHTMLString:myHTML baseURL:nil]; 

      //add webView to your cell 
      myUIWebView.frame = cell.bounds; 
      [cell addSubview:myUIWebView]; 

      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
     } 
+0

, который работал спасибо .. Я сделал только два изменения вашего кода, сначала я удалил autorelease, поскольку использую ARC. Затем, во-вторых, я загрузил ячейку abit differentsly ** [[NSBundle mainBundle] loadNibNamed: @ «AutomotiveSearchCellHtml» владелец: self options: nil]; cell = automativeSearchCellHtml; ** вот так. –

Смежные вопросы