我为来自服务器的动态数据开发了可展开和折叠的表格视图。我已在标题视图中成功显示状态名称,但无法显示与状态名称相关的区域的子数据。
我的数据是 数组中对象的数量不是恒定的。
sectionNames = [ "Home",
"All Products",
"About Us",
"Contact Us",
"Terms and Conditions",
"Privacy Policy",
"Enquiry",
"Register With Us",
"Address Book",
"My Account",
"My Orders",
"Live Chat",
"Logout" ];
sectionItems = [[],
[want to show child data here],
[],[],[],[],[],[],[],[],[],[],[]
];
/////////////////////////////////////////////////////////////////////
_response is
[
{
"name": "name1"
},
{
"name": "name2"
},
{
"name": "name3"
},
{
"name": "name4"
},
{
"name": "name5"
}
}
]
override func numberOfSections(in tableView: UITableView) -> Int {
if sectionNames.count > 0 {
tableView.backgroundView = nil
return sectionNames.count
} else {
let messageLabel = UILabel(frame: CGRect(x: 0, y: 0, width: view.bounds.size.width, height: view.bounds.size.height))
messageLabel.text = "Retrieving data.\nPlease wait."
}
return 0
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (self.expandedSectionHeaderNumber == section) {
let arrayOfItems = self.sectionItems[section] as! NSArray
return arrayOfItems.count;
} else {
return 0;
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "SlideTableViewCell") as? SlideTableViewCell
else{
return UITableViewCell()
}
nameArray = categorytArray.value(forKey: "name") as! NSArray
sectionItems.insert(nameArray, at: 1)
let section = self.sectionItems[indexPath.section] as! NSArray
cell.lblName.textColor = UIColor.black
cell.lblName.text = section[indexPath.row] as? String
return cell
}
我应该如何显示子数据?