【发布时间】:2018-07-19 04:06:38
【问题描述】:
我有 3 个数组,即 todayAry、thisWeekAry、即将到来的Ary,我想根据所有三个数组中的数据创建部分,例如如果所有数组计数大于 0,则为 3 个部分,如果计数为 2,则为两个部分,如果没有数据任何数组然后不创建该部分,那么在 tableView 委托方法中创建它的最佳条件是什么?提供此代码的任何替代方案!! 提前致谢!! 快乐编码!
目前我的代码是:
func numberOfSections(in tableView: UITableView) -> Int {
if self.todayDataAry.count > 0 {
if self.thisWeekDataAry.count > 0 {
if self.upcomingDataAry.count > 0 {
return 3 // all sections today,this week,upcoming
} else {
return 2 //today,this week
}
} else {
if self.upcomingDataAry.count > 0 {
return 2 //today,upcoming
} else {
return 1 //today
}
}
} else {
if self.thisWeekDataAry.count > 0 {
if self.upcomingDataAry.count > 0 {
return 2 //this week, upcoming
} else {
return 1 //this week
}
} else {
if self.upcomingDataAry.count > 0 {
return 1 //upcoming
} else {
return 0 //no data
}
}
}
}
【问题讨论】:
标签: ios arrays iphone swift uitableview