I have two view controllers. I want to make a thing like that when i press "Back" button in SecondViewController, it go back to "FirstViewController" and also update the text of label of "FirstViewController". I have tried below code, its working fine that when i press back button it goes back to "FirstViewController"but the issue is that its not updating the text of the label of "FirstViewController". When i debug my code, control goes to "startSampleProcess" method and update the label's text but when we go back to "FirstViewController" by "processCompleted" method,the old text is displaying there. (I'm doing this work using delegates) Any help would be appreciated.
FirstViewController.h
#import <UIKit/UIKit.h>
//#import "SampleProtocol.h"
@protocol SampleProtocolDelegate <NSObject>
@required
- (void) processCompleted;
@end
// Protocol Definition ends here
@interface FirstViewController : UIViewController{
id <SampleProtocolDelegate> _delegate;
IBOutlet UILabel *myLabel;
}
@property (nonatomic,strong) id delegate;
-(void)startSampleProcess; // Instance method
@end
FirstViewController.m
#import "FirstViewController.h"
@implementation FirstViewController
@synthesize delegate;
-(void)startSampleProcess{
myLabel.text = @"we are back!!!";
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self.delegate
selector:@selector(processCompleted) userInfo:nil repeats:NO];
}
- (void)viewDidLoad{
[super viewDidLoad];
}
@end
SecondViewController.h
#import <UIKit/UIKit.h>
#import "FirstViewController.h"
@interface SecondViewController : UIViewController<SampleProtocolDelegate>{
FirstViewController *sampleProtocol;
}
-(IBAction)CallBack:(id)sender;
@end
SecondViewController.m
#import "SecondViewController.h"
@implementation SecondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad{
[super viewDidLoad];
}
-(IBAction)CallBack:(id)sender{
sampleProtocol = [[FirstViewController alloc]init];
sampleProtocol.delegate = self;
[sampleProtocol startSampleProcess];
}
#pragma mark - Sample protocol delegate
-(void)processCompleted{
[self.navigationController popViewControllerAnimated:TRUE];
}
@end