Question

This might be asked a few time already, how do i call a function when poping back ? NSlog show the text but nothing shows on the view after popping.

list pop to table but the image are not showing

DrinkListViewController

DrinkTableViewController *drinkTable = [[DrinkTableViewController alloc]init];

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
[[self navigationController] popToViewController:obj animated:NO];
                                 [drinkTable addImgViewAfterPopTime];
}

DrinkTableViewController

-(void)addImgViewAfterPopTime
{
    [self performSelector:@selector(addImgViewAfterPop) withObject:nil afterDelay:3];
    NSLog(@"casasasasa");
}
Was it helpful?

Solution

You are creating new instance of DrinkTableViewController when you are calling DrinkTableViewController *drinkTable = [[DrinkTableViewController alloc]init];

so instead of doing this you can do like this:

DrinkListViewController.h

id m_RequestTarget;
SEL m_RequestSelector;

DrinkListViewController.m

-(void)setTarget:(id)inTarget Selector:(SEL)inSelector
{   
    m_RequestTarget = inTarget;
    m_RequestSelector = inSelector;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
   if ([m_RequestTarget respondsToSelector:m_RequestSelector]) {
                    [m_RequestTarget performSelector:m_RequestSelector withObject:nil];
    }
   [[self navigationController] popToViewController:obj animated:NO];

}

and in DrinkTableViewController.m while initializing DrinkListViewController, you call setTarget method as follows:

[theDrinkListViewControllerObj setTarget:self andSelector:@selector(addImgViewAfterPopTime)];

OTHER TIPS

You can make delegate method. and while pushing viewController make the

controller.delegate = self;

and then while popping u can call that delegate method.

use NSNotification to do that instead of this complex situation, post notification when you popback.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top