views:

863

answers:

2

I have seen the sample application of iPhone MP-movie player - controller.

They have added a notification on the sample code.

// Register to receive a notification that the movie is now in memory and ready to play
[[NSNotificationCenter defaultCenter] addObserver:self 
     selector:@selector(moviePreloadDidFinish:) 
     name:MPMoviePlayerContentPreloadDidFinishNotification 
     object:nil];

In above code, When MPMoviePlayerController finishes loading, it invokes moviePreloadDidFinish method.

Similarly, I want to fire an method when user press back button from navigation bar, (back to previous view controller through navigation controller ).

I don't know how to add a notification for that.

Please give some guidance to me if possible.

Thanks in advance for helping me,

Sagar.

+2  A: 

Put your own custom back button in the navigationItem:

UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithImage:yourImage style:UIBarButtonItemStyleBordered target:self action:@selector(goBack)];
self.navigationItem.leftBarButtonItem = btn;
[btn release];

In the goBack method of your viewController, you'll put whatever code you need and then pop the viewController:

- (void)goBack {
 /* your code here */

[self.view.navigationController popToRootViewControllerAnimated:YES];
}
luvieere
See I have added my Own Code.
sugar
A: 

I have set hidden back button of navigation controller.

- (void)viewDidLoad {
    [super viewDidLoad];
    UIBarButtonItem *x=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRewind target:self action:@selector(gotoPreviousView)];
    UINavigationItem *y=self.navigationItem;
    y.hidesBackButton=YES;
    y.leftBarButtonItem=x;
    [x release];
}

-(void)gotoPreviousView{
    MyAccountViewCtr *x=(MyAccountViewCtr*)[self.navigationController.viewControllers objectAtIndex:0];
    [self.navigationController popViewControllerAnimated:YES];
    [x refreshItems];
}
sugar