Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 我们可以在一个tableview numberOfRowsInSection中返回两个数组而不使用swift中的section吗?_Json_Swift_Uitableview_Uicollectionviewcell - Fatal编程技术网

Json 我们可以在一个tableview numberOfRowsInSection中返回两个数组而不使用swift中的section吗?

Json 我们可以在一个tableview numberOfRowsInSection中返回两个数组而不使用swift中的section吗?,json,swift,uitableview,uicollectionviewcell,Json,Swift,Uitableview,Uicollectionviewcell,我正在tableview中显示所有联系人。。但是这里 针对两种情况的两次服务调用1)标记2)过滤器 现在我需要在我的总联系人中检查这两个条件,并相应地显示 我为所有联系人设计了单元格tableview,如下所示: 此处:如果联系人已标记,则我需要显示标记以代替邀请按钮 如果联系人已筛选,则我需要显示onFilter以代替invite按钮,其余应为invite。。。如何在一个单元中完成这一切?请推荐我 最初,我尝试了使用两个原型单元格的tableview,显示如下所示,并正在工作: var

我正在tableview中显示所有联系人。。但是这里

针对两种情况的两次服务调用1)标记2)过滤器

现在我需要在我的总联系人中检查这两个条件,并相应地显示

我为所有联系人设计了单元格tableview,如下所示:

此处:如果联系人已标记,则我需要显示标记以代替邀请按钮

如果联系人已筛选,则我需要显示onFilter以代替invite按钮,其余应为invite。。。如何在一个单元中完成这一切?请推荐我

最初,我尝试了使用两个原型单元格的tableview,显示如下所示,并正在工作:

  var jsonArrayFilter = [ContactJsonFilter]()
 var jsonArrayTagged = [ContactDetailsJsonTagged]()

  func numberOfSections(in tableView: UITableView) -> Int {
    return 2
 }

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    
    if section == 0{
        return jsonArrayTagged.count
    }
    else{
        return jsonArrayFilter.count
    }
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    

if indexPath.section == 0{
    var cell: ContactsTableViewCell = tableView.dequeueReusableCell(withIdentifier: "ContactsTableViewCell", for: indexPath) as! ContactsTableViewCell
                         
        let taggedContactJson = jsonArrayTagged[indexPath.row]
             
                cell.nameLbl.text = taggedContactJson.Name
                cell.empRoleLbl.text = taggedContactJson.phnum
      
                
                let conTaggedStat: Bool = taggedContactJson.isTaggedReq!
                
                if conTaggedStat == true{
                   
                    cell.taggedBtn.setTitle("Tagged", for: .normal)
                }
        
        return cell
                
    }
    
    
    if indexPath.section == 1{
        
        var cell1: ContactsTableViewCell2 = tableView.dequeueReusableCell(withIdentifier: "ContactsTableViewCell2", for: indexPath) as! ContactsTableViewCell2
                                  
                let aJson = jsonArrayFilter[indexPath.row]

        cell1.filterBtn.setTitle("Filter", for: .normal)

                cell1.nameLbl.text = aJson.userName
                cell1.empRoleLbl.text = aJson.phnum

        return cell1
        
    }

    return UITableViewCell()
}
但我需要检查一个单元格中的两个条件,而不是两个单独的单元格中的两个条件。这怎么可能?

编辑:我的两个API结构。。。如何在单个数组中创建它们

struct ContactJsonFilter {

var userId: String?
var userType: String?
var onItag: Bool?
var taggedStat: Bool?
var userName: String?
var phnum: String?

init(userId: String, oniTaag: Bool, tagged: Bool, userName: String, key: String) {

    self.userId = userId
    self.userType = userType
    self.onItag = oniTaag
    self.taggedStat = tagged
    self.userName = userName
    self.phnum = key
}
}
struct ContactDetailsJsonTagged {

var userId: String?
var userType: String?
var fName: String?
var lName: String?
var phnum: String?
var isTaggedReq: Bool?
var status: String?

init(userId: String, userType: String, firstName: String, lastName: String, phone: String, isTaggedWithRequestor: Bool, status: String) {

    self.userId = userId
    self.userType = userType
    self.fName = firstName
    self.lName = lastName
    self.phnum = phone
    self.isTaggedReq = isTaggedWithRequestor
    self.status = status
    
}
}

你可以打10个电话给API的先生。。。。关于编号没有问题:)@jawadAli in
numberofrowsinssection
我们如何调用sir您如何调用第一个API?@jawadAli
if section==0{返回jsonarraytaged.count
if section==1{return jsonArrayFilter.countt
像这样..这里我面临的问题是,如果你创建了一个适当的数据模型,并且条件不同,你可以检查一切。你可以调用10个API的sir…数字没有问题:)@jawadAli in
numberofrowsinssection
我们如何调用sir你如何调用第一个API?@jawadAli
if section==0{return jsonarraytaged.count
如果section==1{return jsonArrayFilter.countt
像这样..这里我面临的问题是,如果您创建了一个适当的数据模型并且条件不同,您可以检查一切。