大佬教程收集整理的这篇文章主要介绍了ios – 将多个原型单元格加载到UITableView中,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
func tableView(tableView: UITableView,cellForRowATindexPath indexPath: NSIndexPath) -> UITableViewCell { let cell: FlightsDetailCell = tableView.dequeueReusableCellWithIdentifier("Cell",forIndexPath: indexPath) as FlightsDetailCell cell.userInteractionEnabled = false if indexPath.section == 0 { cell.graphView.enableBezierCurve = true cell.graphView.enableReferenceYAxisLines = true cell.graphView.enableYAxisLabel = true cell.graphView.colorYaxisLabel = UIColor.whiteColor() cell.graphView.delegate = UIApplication.sharedApplication().delegate as BEMSimpleLineGraphDelegate cell.graphView.datasource = UIApplication.sharedApplication().delegate as BEMSimpleLineGraphDatasource return cell } if indexPath.section == 1 { cell.graphView.enableBezierCurve = true cell.graphView.enableReferenceYAxisLines = true cell.graphView.enableYAxisLabel = true cell.graphView.colorYaxisLabel = UIColor.whiteColor() cell.graphView.delegate = self cell.graphView.datasource = self return cell } if indexPath.section == 2 { let cell2: FlightsInformationCell = tableView.dequeueReusableCellWithIdentifier("Cell2",forIndexPath: indexPath) as FlightsInformationCell cell2.userInteractionEnabled = false return cell2 } return cell }
第0节和第1节正确加载ID为“Cell”的原型单元,但是当我去加载第2部分时,我得到第一个原型单元的另一个实例,减少任何数据,因为它没有被分配一个委托或datasource.否则,单元格分别与“Cell”和“Cell2”的ID设置相同,但是我似乎无法访问“Cell2”.
附加说明:我的故事板中有2个原型单元格,它们都设置相同,因为它们的标识符都标注在相同的框中,继承自己的类,并在我的UITableView中被声明为相同.对于delegate和datasources,我的原始原型单元格保存一个图形(使用BEMSimpleLineGraph),这个单元格的每个实例都有自己的委托和数据源,并在上面的代码中@L_874_10@了动作0和1.
下图(灰色)中的第一个单元格是保存图形的原始单元格,单元格2在白色正下方.
func tableView(tableView: UITableView,cellForRowATindexPath indexPath: NSIndexPath) -> UITableViewCell { cell.userInteractionEnabled = false if indexPath.section == 0 { let cell: FlightsDetailCell = tableView.dequeueReusableCellWithIdentifier("Cell",forIndexPath: indexPath) as FlightsDetailCell cell.graphView.enableBezierCurve = true cell.graphView.enableReferenceYAxisLines = true cell.graphView.enableYAxisLabel = true cell.graphView.colorYaxisLabel = UIColor.whiteColor() cell.graphView.delegate = UIApplication.sharedApplication().delegate as BEMSimpleLineGraphDelegate cell.graphView.datasource = UIApplication.sharedApplication().delegate as BEMSimpleLineGraphDatasource return cell } else if indexPath.section == 1 { let cell: FlightsDetailCell = tableView.dequeueReusableCellWithIdentifier("Cell",forIndexPath: indexPath) as FlightsDetailCell cell.graphView.enableBezierCurve = true cell.graphView.enableReferenceYAxisLines = true cell.graphView.enableYAxisLabel = true cell.graphView.colorYaxisLabel = UIColor.whiteColor() cell.graphView.delegate = self cell.graphView.datasource = self return cell } else { let cell2: FlightsInformationCell = tableView.dequeueReusableCellWithIdentifier("Cell2",forIndexPath: indexPath) as FlightsInformationCell cell2.userInteractionEnabled = false return cell2 }
}
这可以进一步重构以取代重复的代码,但这应该工作…
以上是大佬教程为你收集整理的ios – 将多个原型单元格加载到UITableView中全部内容,希望文章能够帮你解决ios – 将多个原型单元格加载到UITableView中所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。