hello there! i`m very confused about delegation..
i got the theorical idea of delegation but i just cant convert it to code..
i`ll explain:
lets say i`ve created a project in xcode and i have my viewcontroller.h\m and also my appdelegate.h\m now lets say i want to use:
this method is in the appdelegate.m file -for three days i`m trying to do this simple practice:
when didFinishLaunching occur set the IBOutlet Label (ivar of viewcontroller)
like this
code 4 better understanding:
AppDelegate.h
AppDelegate.m
the code is not working because i dont know how to transfer the label.text change to the viewcontroller... i also noticed that in my AppDelegate.m file that when i tried to change the label text in my viewcontroller object like so:
it appeard as NULL in the later NSLog call!
i`m realy confused because i dont know how to use delegation in my app..
i know i can use Notification center for those things but i want to understand old fashion delegation usage.
i need help i`m frustrated... tnq!
i got the theorical idea of delegation but i just cant convert it to code..
i`ll explain:
lets say i`ve created a project in xcode and i have my viewcontroller.h\m and also my appdelegate.h\m now lets say i want to use:
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
when didFinishLaunching occur set the IBOutlet Label (ivar of viewcontroller)
like this
Code:
label.text = "@dude";
code 4 better understanding:
AppDelegate.h
Code:
#import <UIKit/UIKit.h>
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
ViewController *myvc;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *myvc;
@end
AppDelegate.m
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.myvc = [[ViewController alloc] initWithNibName:@"view1" bundle:nil];
self.myvc.label.text = @"dude";
NSLog(@"hey from appdelegate wtf");
NSLog(@"label = %@", self.myvc.label.text);
// Override point for customization after application launch.
return YES;
}
the code is not working because i dont know how to transfer the label.text change to the viewcontroller... i also noticed that in my AppDelegate.m file that when i tried to change the label text in my viewcontroller object like so:
Code:
self.myvc.label.text = @"dude";
it appeard as NULL in the later NSLog call!
i`m realy confused because i dont know how to use delegation in my app..
i know i can use Notification center for those things but i want to understand old fashion delegation usage.
i need help i`m frustrated... tnq!