Ios 在表视图中选择特定单元格时,如何展开该单元格或将其替换为其他单元格

Ios 在表视图中选择特定单元格时,如何展开该单元格或将其替换为其他单元格,ios,swift,uitableview,Ios,Swift,Uitableview,我已经在SO中提出了这个疑问/问题。但没有得到解决。请帮帮我 我有一个表视图,它将显示10个数据之前的名称数据列表。但我需要的是,当用户按下任何一个手机时,该手机应该被另一个手机取代,这个手机有一些图像、电话号码和相同的数据名。如何做到这一点 我有两个xib:1。正常细胞,2。可扩展/替换单元 这是我的viewconrolelr.swift import UIKit class ViewController: UIViewController, UITableViewDelegate, UIT

我已经在SO中提出了这个疑问/问题。但没有得到解决。请帮帮我

我有一个表视图,它将显示10个数据之前的名称数据列表。但我需要的是,当用户按下任何一个手机时,该手机应该被另一个手机取代,这个手机有一些图像、电话号码和相同的数据名。如何做到这一点

我有两个xib:
1。正常细胞,2。可扩展/替换单元

这是我的
viewconrolelr.swift

import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
    
    @IBOutlet weak var tableView: UITableView!
    
    @IBOutlet weak var Resultcount: UILabel!
    
    var tableData = ["thomas", "Alva", "Edition", "sath", "mallko", "techno park",... till 10 data]
    let cellSpacingHeight: CGFloat = 5

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
     
        var nib = UINib(nibName:"customCell", bundle: nil)
        tableView.registerNib(nib, forCellReuseIdentifier: "cell")
        Resultcount.text = "\(tableData.count) Results"
        
        
        
    }
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
         return self.tableData.count
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return cellSpacingHeight
    }
    
    // Make the background color show through
    func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let headerView = UIView()
        headerView.backgroundColor = UIColor.clearColor()
        return headerView
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
     
        
        var cell:customCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! customCell
        
        
        cell.vendorName.text = tableData[indexPath.section]
        
        return cell
        
        
    }


  

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}
启动我的手机将如下所示:

当我按下那个单元格时,我需要这样做,替换下面的单元格:

但当我再次按下同一个单元格时,它会再次转到正常单元格


如何做到这一点???

首先修改tableView:cellForRowAtIndexPath:实现,如下所示。然后您需要实现click处理程序。一种方法是在迈塞尔班。另一种可能是覆盖。如果不了解更多您想要的内容(例如,多选与单选),就很难给出实际的代码,但这里有一些东西

BOOL clickedRows[MAX_ROWS]; // Init this array as all false in your init method. It would be better to use NSMutableArray or something similar...

// selectRowAtIndexPath code
int row = indexPath.row
if(clickedRows[row]) clickedRows[row]=NO; // we reverse the selection for the row
else clickedRows[row]=YES;
[self.tableView reloadData];

// cellForRowAt... code
MyCell *cell = [tableView dequeueResuableCell...
if(cell.clicked) { // Nice Nib
     [tableView registerNib:[UINib nibWithNibName... for CellReuse...
} else { // Grey Nib
     [tableView registerNib:[UINib nibWithNibName... for CellReuse...
}

您需要在xib上创建两个独立的单元格。然后你可以使用check加载。你可以复制和粘贴它,这将非常有效。 在cellForRowAt中,如下所示:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if selectedIndexPath == indexPath && self.isExpand  == true{
            let cell = tableView.dequeueReusableCell(withIdentifier: "LeaveBalanceExpandedCell", for: indexPath) as! LeaveBalanceExpandedCell
            cell.delegate = self
            return cell
        }
        else{
            let cell = tableView.dequeueReusableCell(withIdentifier: "LeaveBalanceNormalCell", for: indexPath) as! LeaveBalanceNormalCell
            return  cell
        }
    }
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
//        cell.animateCell(cell)
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if selectedIndexPath == indexPath{
    if isExpand == true{
        self.isExpand = false
    }
    else{
        self.isExpand = true
    }
    }
    else{
        selectedIndexPath = indexPath
        self.isExpand = true
    }
        self.tableView.reloadData()
    }

当我点击任何单元格时,你能给我一些完整的代码解释一下索引路径下单元格行的方法来改变单元格的格式吗。我在勒纳的部分。所以知道它是什么样子会很有用..有这个兄弟的解决方案吗?事实上,我在寻找相同的解决方案……我也在寻找相同的解决方案。伙计们,如果你们有一些演示或代码,请帮助我。最终,我成功地做到了这一点。