Ios 如何在tableview中添加除swift中的两个单元格之外的额外行
HomeVC中的此结构:Ios 如何在tableview中添加除swift中的两个单元格之外的额外行,ios,swift,uitableview,row,Ios,Swift,Uitableview,Row,HomeVC中的此结构: struct JsonData{ var name: String = "" var categoryname: String = "" var customerdetails: [cDetails] = [cDetails]() init(name: String, categoryname: String, customerdetails: [cDetails]){ self.name = name self.categoryname = categorynam
struct JsonData{
var name: String = ""
var categoryname: String = ""
var customerdetails: [cDetails] = [cDetails]()
init(name: String, categoryname: String, customerdetails: [cDetails]){
self.name = name
self.categoryname = categoryname
self.customerdetails = customerdetails
}
}
struct cDetails{
var dValue: String = ""
init(dValue: String) {
self.dValue = dValue
}
}
在这里,我可以为整个categoryname添加额外的行,但在该categoryname中,除了第一个和最后一个BNName,我不需要额外的行,如何做到这一点
我的意思是mobile postpaid
是categoryname,而tableview内容是bname
值,在tableview的第一个和最后一个bname中,我不需要额外的行,如何做到这一点
这是我的密码:
var selectedBiller: JsonData?
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
self.rowCount = selectedBiller?.customerdetails.count ?? 0
if selectedBiller?.categoryname == "Mobile Postpaid"{
if selectedBiller?.name == "vodaphonepostpaid(fetch)" && selectedBiller?.name == "airtelpostpaid(fetch)"
{
return selectedBiller?.customerdetails.count ?? 0
}//if
else{
return self.rowCount! + 1
}
}
i give like this also i am getting extra row
else{
return selectedBiller?.customerdetails.count ?? 0
}
}
return 1
}
在这里,对于所有移动indexath,我得到了额外的一行,但除了第一行和最后一行之外,我需要
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 {
cell = tableView.dequeueReusableCell(withIdentifier: "textfieldCell", for: indexPath) as? DetailTableViewCell
if self.rowCount! - 1 >= indexPath.row
{
if let value = selectedDetail?.customerdetails[indexPath.row] {
cell?.searchTextfield.text = value.dValue
} else {
cell?.searchTextfield.text = "missing data"
}
}
else
{
cell?.searchTextfield.text = "Amount"
}
}
试着换一行-
if selectedBiller?.name == "vodaphonepostpaid(fetch)" && selectedBiller?.name == "airtelpostpaid(fetch)"
到
试着换一行-
if selectedBiller?.name == "vodaphonepostpaid(fetch)" && selectedBiller?.name == "airtelpostpaid(fetch)"
到
在numberOfRowsInSection内使用了此行
if selectedBiller?.name == "vodaphonepostpaid(fetch)" || selectedBiller?.name == "airtelpostpaid(fetch)
而不是
if selectedBiller?.name == "vodaphonepostpaid(fetch)" && selectedBiller?.name == "airtelpostpaid(fetch).
它将对您有效在numberOfRowsInSection中使用此行
if selectedBiller?.name == "vodaphonepostpaid(fetch)" || selectedBiller?.name == "airtelpostpaid(fetch)
而不是
if selectedBiller?.name == "vodaphonepostpaid(fetch)" && selectedBiller?.name == "airtelpostpaid(fetch).
如果我错了,你想在用户点击tableViewCell时在下面添加一个新的单元格,但是有一些限制,比如用户点击vodaphonepostpaid(fetch)和airtelpostpaid(fetch),你不想要,对吧?@SGDev,对不起,我把每一个都弄错了,我已经编辑了我的帖子。请帮助,我可以为整个类别添加额外的单元格Name==“Mobile Postpaid”,但在该类别中,除了
vodaphonepostpaid(fetch)和airtelpostpaid(fetch)
B名称值我需要添加额外的行。您仍然让我感到困惑,很简单,vodaphonepostpaid(fetch)和airtelpostpaid(fetch)的情况下,您不需要a单元格
?@SGDev-Oops真的,是的,如果vodaphonepostpaid(fetch)和airtelpostpaid(fetch)那么我不需要cell?.searchTextfield.text=“Amount”
cell?.searchTextfield.text=value.dValue@SGDev,非常感谢你纠正了我的错误,当用户单击tableViewCell时,您想在下面添加一个新的单元格,但有一些限制,例如如果用户单击vodaphonepostpaid(fetch)和airtelpostpaid(fetch),您不想要,对吗?@SGDev,对不起,我把每个单元格都弄混了,我已经编辑了我的帖子。请帮助,我可以为整个类别添加额外的单元格Name==“Mobile Postpaid”,但在该类别中,除了vodaphonepostpaid(fetch)和airtelpostpaid(fetch)
B名称值我需要添加额外的行。您仍然让我感到困惑,很简单,vodaphonepostpaid(fetch)和airtelpostpaid(fetch)的情况下,您不需要a单元格
?@SGDev-Oops真的,是的,如果vodaphonepostpaid(fetch)和airtelpostpaid(fetch)那么我不需要cell?.searchTextfield.text=“Amount”
cell?.searchTextfield.text=value.dValue@SGDev,非常感谢您的纠正。对不起,没有检查评论,它正在显示中。对不起,没有检查评论,它正在显示更多