无法在UITableView Swift中隐藏空单元格

时间:2014-06-28 20:25:53

标签: ios iphone uitableview swift

我在swift应用程序中使用UITableView,并使用我自己的自定义UITableViewCell。

当试图隐藏UITableView中的空单元格时,它仍然具有白色背景。

在UITableView下我有一个背景图片(UImageView)。

我已经尝试隐藏这些单元格,实际上它们是隐藏的,但我仍然有白色背景,使用此代码:

override func viewDidLoad() {
    super.viewDidLoad()
    var tblView =  UIView(frame: CGRect(x: 0,y: 0,width: 0,height: 0))
    tblView.backgroundColor = UIColor.clearColor()
    tableView.tableFooterView = tblView

    var nipName=UINib(nibName: "CustomCell", bundle:nil)
    self.tableView.registerNib(nipName, forCellReuseIdentifier: "CustomCell")
}

6 个答案:

答案 0 :(得分:31)

更清洁的解决方案是:

tableView.tableFooterView = UIView(frame: CGRectZero)

不需要其他任何东西。

答案 1 :(得分:25)

这是解决方案:

tableView.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
tableView.tableFooterView?.isHidden = true
tableView.backgroundColor = UIColor.clear

答案 2 :(得分:3)

SWIFT 3

tableView.tableFooterView = UIView(frame:.zero)

答案 3 :(得分:0)

针对此问题的另一个更简单的解决方案是使用tableView的图像设置背景。如果您只需要非数据单元格的白色背景,则图像应为纯白色,或者您也可以为自己设置自定义图像tableview background.So数据与单元格将具有正常背景,对于非数据单元格,它将显示您的背景图像:

 self.tableViewName.backgroundColor = UIColor (patternImage: UIImage(named:
 "imageName.jpg")!)

答案 4 :(得分:0)

在Swift 3.0中,这些都可以为我工作

方法 - 1

let footerView =  UIView(frame: CGRect.zero)
tableView.tableFooterView = footerView
tableView.tableFooterView?.isHidden = true
tableView.backgroundColor = UIColor.clear()

方法 - 2

 tableView.tableFooterView = UIView(frame: CGRect.zero)

答案 5 :(得分:0)

Swift 3 :最简单的方法

            var client = new SendGridClient(apiKey);
            EmailAddress from = new 
            EmailAddress("a.b@mycompany.com", "Ashutosh");
            List<EmailAddress> tos = new List<EmailAddress>
            {
                new EmailAddress("a.b@mycompany.com", 
                                 "Ashutosh"),
            };

            StringBuilder emailBodyContent = new StringBuilder();
            var textContent = "Hi, ";
            emailBodyContent.AppendFormat("<p>Hi, </p>");
            emailBodyContent.AppendFormat("<p>This is your email.</p>");




            var emailSubject = "Attachment names are not unique";

            msg = MailHelper.CreateSingleEmailToMultipleRecipients(from, 
            tos, emailSubject, textContent, emailBodyContent.ToString());
            var response = await client.SendEmailAsync(msg);
相关问题