0

在 iOS 7 中,tableview 中的 webview 没有显示在 iOS 5 中正常工作的位置。在 iOS 7 中,创建了一个示例应用程序,其中包含 tableview 中的 webview。它工作正常。找了半天,发现可能是手势识别的原因,tableview中的Webview没有显示出来。我在我的示例应用程序中测试了这个场景。但它工作正常。所以手势识别器没有问题。

知道为什么 tableview 中的 webview 没有在 iOS 7 中显示吗?

这是要检查的代码:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
     return [app.resultsDic count];

}


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
  return  [NSString stringWithFormat:@"%d",section];    

}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{   

   return 1;


}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 150;
}


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

     static NSString *CellIdentifier = @"Cell";


    UIWebView *webView ;

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;


    }
    NSUInteger row = [indexPath section];

    if ( [app.resultsDic count]>0 )
    {
        NSArray *cellSubviews = [cell subviews];
        for (UIView *currSubView in cellSubviews) {
            [currSubView removeFromSuperview];
        }
        webView = [[UIWebView alloc] initWithFrame:CGRectMake(15, 8, 280, 140)];
        webView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.jpg"]];

        [cell addSubview:webView];

        //Retrieving Data into Dictionary and formatting the data using htmlString

        NSDictionary *resDict = [app.resultsDic valueForKey:[NSString stringWithFormat:@"%d",row]];

        NSMutableString *htmlString = [[NSMutableString alloc] init];
        NSString *initialString = [NSString stringWithFormat:@"<table>"];
        NSString *endString = [NSString stringWithFormat:@"</table>"];
        [htmlString appendString:initialString];
        for (int e = 0 ; e < [[resDict allKeys] count]; e++) {
            NSString *currentKey = [[resDict allKeys] objectAtIndex: e];


            [htmlString appendFormat:@"<tr><td ><b>%@</b></td><td>:</td><td><font color=DarkBlue>%@</font></td></tr>", currentKey,[resDict objectForKey:currentKey]];

        }
        [htmlString appendString:endString];
        NSString *cssString=[NSString stringWithFormat:@"table { width:100%; font-size:12px;font-family:Verdana}"];

        NSString *htmlString1 = [NSString stringWithFormat:@"<html> <head>     <style type=\"text/css\"> %@ </style> </head> <body> %@ </body> </html>", cssString, htmlString];  

        [webView loadHTMLString:htmlString1 baseURL:nil];

        [webView.scrollView setBounces:NO];

    }
        return cell;

}

谢谢

4

3 回答 3

0

您可以尝试替换以下代码吗

    NSString *htmlString1 = [NSString stringWithFormat:@"<html> <head>     <style type=\"text/css\"> %@ </style> </head> <body> %@ </body> </html>", cssString, htmlString];  

    NSString *htmlString1 = [NSString stringWithFormat:@"<html> <head>     <style> %@ </style> </head> <body> %@ </body> </html>", cssString, htmlString];  
于 2013-11-15T11:40:34.203 回答
0
    I resolved this issue in iOS 7.

  //In ios 5, I have added this code for removing the subviews in webview.

      NSArray *cellSubviews = [cell subviews];

            for (UIView *currSubView in cellSubviews) 
            {
                [currSubView removeFromSuperview];
            }

    //In ios 7 , I have removed the above code. Because we need not to write any code for removing the subviews in webview.
于 2014-02-18T12:43:31.183 回答
0

这个简单的代码在 iOS7 中对我有用

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

    UIWebView *web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
    [web loadHTMLString:@"im a <b>webview</b>" baseURL:nil];
    web.userInteractionEnabled = NO;
    [cell.contentView addSubview:web];

    return cell;
}
于 2013-11-15T10:46:20.243 回答