Bigair
Bigair

Reputation: 1592

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.

Upvotes: 9

Views: 12644

Answers (2)

Hardik
Hardik

Reputation: 139

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
}

Upvotes: 7

Vvk
Vvk

Reputation: 4043

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.

Upvotes: 12

Related Questions