I have been stuck here.
I have a NSString in Appdelegate. And I have two views called firstview,second view.In first view I have a label and set text from stringvariable which is in Appdelegate .When I click on the button in first view,It goes to the secondview(added the second view to first view as a subview).In second view I have a back button.when I click the back button it is displaying the first view ( Here I am setting the value which is in the appdelegate.And then used this [self.view removeFromSuperview]
).The Problem is first view is appearing but label value is not updating.Can any body tell me how to update the Labeltext.Kindly tell me.
Appdelegate.h
#import <UIKit/UIKit.h>
@class FirstView;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
NSString *str1;
}
@property (nonatomic,retain) NSString *str1;
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@end
Appdelegate.m
#import "AppDelegate.h"
#import "FirstView.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize viewController = _viewController;
@synthesize str1;
- (void)dealloc
{
[_window release];
[_viewController release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[FirsView alloc] initWithNibName:@"FirstView" bundle:nil] autorelease];
self.str1 = @"view1";
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
FirstView.h
#import <UIKit/UIKit.h>
#import "secondView.h"
@interface FirstView : UIViewController
{
IBOutlet UILabel *btn;
secondView *cont;
}
-(IBAction)gotoView2:(id)sender;
@end
FirstView.m
#import "FirstView.h"
-(IBAction)gotoView2:(id)sender
{
cont = [[secondView alloc] initWithNibName:@"secondView" bundle:nil];
[self.view addSubview:cont.view];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
AppDelegate *del = [[UIApplication sharedApplication] delegate];
[btn setTitle:del.str1];
}
**SecondView.h**
#import <UIKit/UIKit.h>
@interface SecondView : UIViewController
{
}
-(IBAction)goBack:(id)sender;
@end
SecondView
#import "SecondView.h"
#import "AppDelegate.h"
@implementation SecondView
-(IBAction)gotoView1:(id)sender
{
AppDelegate *del = [[UIApplication sharedApplication] delegate];
[del setStr1:@"Home"];
[self.view removeFromSuperView];
}