swift 创建了 uitableview 部分
swift created sections uitableview
我是 swift 和面向对象编程的新手,
我正在尝试在我的 UI table 视图
的部分中显示一些日期
我想手动修改这些section的Header
这是我的代码:
let section1 =
["this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",]
let section2 =
["this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",]
然后我的加载方法
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 5
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return self.section1.count;
}
func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell:UITableViewCell = UITableViewCell(style:UITableViewCellStyle.Default, reuseIdentifier:"cell")
cell.textLabel!.text = section1[indexPath.row]
cell.textLabel!.numberOfLines = 3
return cell
}
我已经为它们创建了多个常量,但它们不需要分开(它们是常量,不会改变)
我的数据只需要 5 个不同的部分
非常感谢
代替索引路径处行的单元格实现此委托方法:
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 0 {
tableView.headerViewForSection(section)?.textLabel.text = section1[section]
} else if section == 1 {
//and so on for the number of sections you need. 5 or what evet.
}
}
我是 swift 和面向对象编程的新手,
我正在尝试在我的 UI table 视图
的部分中显示一些日期我想手动修改这些section的Header
这是我的代码:
let section1 =
["this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",]
let section2 =
["this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",
"this is used tot test the lenght of the text",]
然后我的加载方法
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 5
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return self.section1.count;
}
func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell:UITableViewCell = UITableViewCell(style:UITableViewCellStyle.Default, reuseIdentifier:"cell")
cell.textLabel!.text = section1[indexPath.row]
cell.textLabel!.numberOfLines = 3
return cell
}
我已经为它们创建了多个常量,但它们不需要分开(它们是常量,不会改变)
我的数据只需要 5 个不同的部分
非常感谢
代替索引路径处行的单元格实现此委托方法:
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 0 {
tableView.headerViewForSection(section)?.textLabel.text = section1[section]
} else if section == 1 {
//and so on for the number of sections you need. 5 or what evet.
}
}