Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
346 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...