首页 \ 问答 \ 细胞背景视图不填充整个细胞(Cell background view not filling the whole cell)

细胞背景视图不填充整个细胞(Cell background view not filling the whole cell)

我正在为UITableView使用单独的UITableView ,当我设置此单元格的背景视图时,它似乎将图像填充在一个框而不是整个单元格中。 单独的UITableViewCellUITableView's行的尺寸均为280x44 。 这是一个看起来像的图像: 在此处输入图像描述

这是我为编写单元格的背景视图而编写的代码:

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

    PBDashboardSummarizedCell *cell = (PBDashboardSummarizedCell *)[tableView dequeueReusableCellWithIdentifier:@"PBDashboardSummarizedCell"];
    if (!cell) {
        cell = [PBDashboardSummarizedCell standardCell];
    }
     if(datapickup.isexpanded==YES)
          {
           UIImageView *av = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 280, 44)];
              av.opaque = NO;
              av.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"dashboardCellEffect.png"]];
              cell.backgroundView = av;          //tried this
             // [cell setBackgroundView:av];     //and this also... but still image is set in the box and not the whole cell
          }
          else{
              UIImageView *av = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 280, 44)];
              av.backgroundColor = [UIColor clearColor];
              av.opaque = NO;
              cell.backgroundView = av;

        }

          return cell;
}

I am using a separate UITableViewCell for the UITableView and when i set background View of this cell, it seems to fill the image in a box rather than the whole cell. The dimensions of both separate UITableViewCell and UITableView's row are 280x44. Here's an image of what it looks like: enter image description here

Here's the code that i am writing for setting the background view of the cell:

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

    PBDashboardSummarizedCell *cell = (PBDashboardSummarizedCell *)[tableView dequeueReusableCellWithIdentifier:@"PBDashboardSummarizedCell"];
    if (!cell) {
        cell = [PBDashboardSummarizedCell standardCell];
    }
     if(datapickup.isexpanded==YES)
          {
           UIImageView *av = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 280, 44)];
              av.opaque = NO;
              av.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"dashboardCellEffect.png"]];
              cell.backgroundView = av;          //tried this
             // [cell setBackgroundView:av];     //and this also... but still image is set in the box and not the whole cell
          }
          else{
              UIImageView *av = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 280, 44)];
              av.backgroundColor = [UIColor clearColor];
              av.opaque = NO;
              cell.backgroundView = av;

        }

          return cell;
}

原文:https://stackoverflow.com/questions/15353020
更新时间:2023-08-19 20:08

最满意答案

是否有可能遍历所有包含的li元素并提取它们的值?

来自OP的评论

Doctype是HTML 5,它是有效的代码。 - 拉杜

在这种情况下,可以使用以下XPath表达式

div//li//text()

这将选择作为当前节点的子元素的任何div元素的后代的所有li元素的后代的所有文本节点。

使用XPath表达式来选择XML中的节点(以及HTML5是格式良好的XML)是建议的,最直接和更可靠的方式,因为难以构造,难以测试,难以理解和维护正则表达式。

这是一个完整的代码示例

using System;
using System.Xml;

class TestXPath
{
    static void Main(string[] args)
    {
        string html5Text =
@"<html>
 <head>
 </head>
 <body>
  <div>
   <ul>
    <li>Line 1</li>
    <li>Line 2</li>
    <li>Line 3</li>
   </ul>
  </div>
 </body>
</html>";

        XmlDocument doc = new XmlDocument();
        doc.LoadXml(html5Text);

        string xpathExpr = @"/*/*/div//li//text()";

        XmlNodeList selection = doc.SelectNodes(xpathExpr);

        foreach (XmlNode node in selection)
        {
            Console.WriteLine(node.OuterXml);
        }

    }
}

执行上述应用程序时,会生成所需的正确结果

Line 1
Line 2
Line 3

Is it possible to iterate through all the li elements contained and extract their values?

From comment of the OP:

Doctype is HTML 5 and it is valid code. – Radu

In this case one can just use the following XPath expression:

div//li//text()

This selects all text nodes that are descendents of all li elements that are descendents of any div element that is a child of the current node.

Using an XPath expression to select nodes in an XML (and HTML5 is well-formed XML) is the recommended, most straightforward and more reliable way than doing this with difficult to construct, difficult to test and difficult to understand and maintain regular expressions.

Here is a complete code example:

using System;
using System.Xml;

class TestXPath
{
    static void Main(string[] args)
    {
        string html5Text =
@"<html>
 <head>
 </head>
 <body>
  <div>
   <ul>
    <li>Line 1</li>
    <li>Line 2</li>
    <li>Line 3</li>
   </ul>
  </div>
 </body>
</html>";

        XmlDocument doc = new XmlDocument();
        doc.LoadXml(html5Text);

        string xpathExpr = @"/*/*/div//li//text()";

        XmlNodeList selection = doc.SelectNodes(xpathExpr);

        foreach (XmlNode node in selection)
        {
            Console.WriteLine(node.OuterXml);
        }

    }
}

when the above application is executed, the wanted, correct result is produced:

Line 1
Line 2
Line 3

相关问答

更多
  • 听起来您希望能够将HTML字符串的长度截断为文本字符串,例如考虑以下HTML: 'foo bar' 在这种情况下,HTML的长度为14个字符,文本为7.您希望能够将其截断为X个文本字符(例如2),以便新的HTML现在是: 'fo' 披露:我的回答使用了我开发的库。 您可以使用HTMLString库 - Docs : GitHub 。 该库使这项任务非常简单。 要使用HTMLString截断我们上面概述的HTML(例如2个文本字符),您将使用以下代码: var myString ...
  • 您可以使用dom方法处理每个文本节点。 此方法为第一个参数提供一个父节点,并遍历其所有子节点,并使用作为第二个参数传递的函数处理文本节点。 例如,该功能是您可以在测试节点的数据上进行操作的位置,以查找或替换,删除或包装以“突出显示”范围显示的文本。 您可以仅使用第一个参数调用该函数,并且它将返回一个文本节点数组,然后可以使用该数组来操作文本 - 在这种情况下,数组项是每个节点,并且具有数据,父代和兄弟。 document.deepText= function(hoo, fun){ var A= [] ...
  • 那么, Nokogiri::HTML将文本解析为Nokogiri::HTML对象而不是HTML。 相反,将要解析的文件上的所有Ruby代码转换为纯HTML。 然后使用html_safe将文本转换为有效的HTML。 Well, Nokogiri::HTML parses the text to a Nokogiri::HTML object not to HTML as you need it. Instead, convert all the Ruby code on the file you want t ...
  • 事实证明,对我来说最简单的方法是在将它放入BeautifulSoup之前拆分它。 所以我所做的是使用以下代码拆分它然后我(当前)编写一个函数来处理破坏文本很好。 from bs4 import BeautifulSoup as Soup with open('found1.html', 'r') as f: html = f.read() sections = html.split('') # ...
  • 我希望在“联系我们”页面中自动显示更改 只需将“ 联系我们”页面设为JSP,即可从存储它的位置中提取电话号码。 JSP用于动态网页,它自动更改内容。 这就是你想要的。 I want the changes to be visible automatically in the Contact Us page Just make the Contact Us page a JSP, which extracts the phone number from where you have stored it. JS ...
  • 也许尝试unescape或decodeuri,这是标准的旧js方法。 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape 如果不是只对已知的char集进行字符串替换(“与”相同) Maybe try unescape or decodeuri, which are standard old js methods. https://developer.mozilla.org/en-U ...
  • 是否有可能遍历所有包含的li元素并提取它们的值? 来自OP的评论 : Doctype是HTML 5,它是有效的代码。 - 拉杜 在这种情况下,可以使用以下XPath表达式 : div//li//text() 这将选择作为当前节点的子元素的任何div元素的后代的所有li元素的后代的所有文本节点。 使用XPath表达式来选择XML中的节点(以及HTML5是格式良好的XML)是建议的,最直接和更可靠的方式,因为难以构造,难以测试,难以理解和维护正则表达式。 这是一个完整的代码示例 : using System; ...
  • 您必须使用AJAX呼叫请求文件。 然后你需要遍历每一行响应并生成DOM元素(在这种情况下是li )并在其中输入行。 之后,将每个li元素插入到你的ul列表中。 你可以使用jQuery来实现它,因为你可能是JavaScript的新手,这可能是最简单的方法。 你需要做的是首先请求文件: $.ajax('url/to/your/file', { success: fileRetrieved }); 现在,在检索文件后, jQuery将调用fileRetrieved方法,因此我们必须创建它: functi ...
  • 以下代码对我有用 public static string GetComments(string html) { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); string s = ""; foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//ol")) { s += node.OuterHtml; } ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。