Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewWillAppear on UITableViewCell?

Is there any way to perform something like ViewWillAppear on UITableViewCell?

UITableViewDelegate methods (like willDisplayCell) only works when cells appear by scrolling.

In my situation, I need to detect cell appearance in a situation like user moves to another Tab and gets back to the UITableView.

I was able to solve the my problem using indexPathsForVisibleRows method but this doesn't seem to be a smart way of doing it.

like image 206
Bigair Avatar asked Feb 09 '16 04:02

Bigair


Video Answer


2 Answers

I'm not sure whether this will work for you as you want to do something on tab change as well otherwise it will work.

I know I am answering too late, but I am answering to help others who view this post.

So you can try this: (Objective-C)

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell  
                                         forRowAtIndexPath:(NSIndexPath *)indexPath {
    // Do what ever you want
}

(Swift)

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
    // Do what ever you want
}
like image 54
Hardik Avatar answered Oct 21 '22 10:10

Hardik


Yes. you have to use awakeFromNib meyhod inside the m file. this method is always call first.

-(void)awakeFromNib{

}

if visible cell not load then you have to reload your tableview.

 tableView.reloadData()

Hope it helps you.

like image 32
Vvk Avatar answered Oct 21 '22 08:10

Vvk