在tableView swift中更新标题 [英] Update the header in tableView swift

查看:50
本文介绍了在tableView swift中更新标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试更新在添加新行而不重新加载整个节的情况下在节标题中创建的label.text.

当前,我找到了一个解决方案,但是它需要很多 if 语句.我发现节的标题实际上也是一行,行的数量取决于iPhone的cpu架构,如果是32,则行号是2147483647,如果是64bit,则行号是9223372036854775807.

我可以使用iPhone 5

  self.tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow:2147483647,inSection:1)],withRowAnimation:.Fade) 

其中2147483647是标题的行号.... cool,对吗?

现在我知道这不是一个好方法,我必须对电话版本进行检查.还有另一种方法可以做到这一点,或者我做的还可以吗?

解决方案

制作UILabel对象

  var lbl_header = UILabel()func tableView(tableView:UITableView,viewForHeaderInSection部分:Int)->UIView?{self.lbl_header.frame = CGRectMake(0,0,320,15)self.lbl_header.text =测试"self.lbl_header.backgroundColor = UIColor.redColor()返回self.lbl_header;} 

现在您要更改UILabel的文本对于前.我点击按钮更改标签的文本

  @IBAction函数update_lbl_click(发送者:UIButton){self.lbl_header.text =你好"} 

它将lbl_header的文本更改为Hello ...

I'm trying to update the label.text I create in the header of a section when I add a new row without reloading the entire section.

Currently I found a solution but it requires a lot of if statements. I found out that the header of a section is actually a row as well, and the number of the row depends on the cpu architecture the iPhone has, if it's 32 the row number is 2147483647 if it's 64bit the row number is 9223372036854775807.

for iPhone 5 I do

self.tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow:2147483647, inSection:1)], withRowAnimation: .Fade)

where 2147483647 is the row number of the header, ....cool, right?

Now I know this is not a good way to do it and I have to implement checks for the phone version. Is there another way to do this or the way I do it is fine?

解决方案

Make object of UILabel

 var lbl_header = UILabel()


 func tableView(tableView: UITableView, viewForHeaderInSection  section: Int) -> UIView?
  {

    self.lbl_header.frame = CGRectMake(0, 0, 320, 15)
    self.lbl_header.text = "Test"
    self.lbl_header.backgroundColor = UIColor.redColor()
  return self.lbl_header;

  }

Now it you want to change UILabel's text For ex. i click on button change label's text

  @IBAction func update_lbl_click(sender: UIButton)
   {
     self.lbl_header.text = "Hello"
   }

It will change lbl_header's text to Hello...

这篇关于在tableView swift中更新标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆