Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
348 views
in Technique[技术] by (71.8m points)

ios - UITableView set tableview row hidden

I have a custom tableview cell in grouptableview. And I have one hidden. I then have to make it visible. Cell tag is 3.

This is not working my code:

if (self.tableView.tag == 3) {
                self.tableView.hidden = NO; //Not working.
            }

Just i need make a one row is visible. I hope you understand.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In SWIFT you need to do two things,

  1. HIDE your cell. (because reusable cell may conflict)

  2. Set Height of cell to ZERO.

Look at here,

  1. HIDE you cell.

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let myCell:UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cellID",for: indexPath) as! UITableViewCell
    
        if(indexPath.row < 2){
            myCell.isHidden = true
        }else{
            myCell.isHidden = false
        }
    
        return myCell
    }
    
  2. Set Height of cell to ZERO.

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        var rowHeight:CGFloat = 0.0
    
        if(indexPath.row < 2){
            rowHeight = 0.0
        }else{
            rowHeight = 55.0    //or whatever you like
        }
    
        return rowHeight
    } 
    

Using this you can remove reusable cell conflict issues.

You can do the same for cell?.tag also to hide specific cell by tag.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...