Hi i have a problem with pasing values to one class from other. Basically in my project i have a class placeTableView which is table view class.
in placesTableView.m
{
mapView *map=[[mapView alloc]init];
map.townName=@"london";
}
mapView.h - a class where delegate is defined and from this class i want to send data to confirmController
@protocol mapViewDelegate;
@interface mapView : UIViewController {
id <mapViewDelegate> delegate;//
}
@property (nonatomic, assign) id delegate;//
@end
@protocol mapViewDelegate <NSObject>//
-(void)sendAStringToAnotherView:(NSString*)string;
@end
mapView.m
@synthesis townName;
-(void)viewDidLoad{
label.text=townName;//townName is getting value from previous view n showing here.
NSLog(@"%@",townName);//it shows value of townName so townName definetly contains value
// NSString *a=[NSString stringWithFormat:@"%@",townName];
[delegate sendAStringToAnotherView:townName]; // this is sending method. i think problem is here
}
confirmController.m – a class where data sent
-(void)viewDidLoad{
mapView *myViewControllerPointer=[[mapView alloc] init];
myViewControllerPointer.delegate = self;//
[self.view addSubview:self.myViewControllerPointer.view];
}
-(void)sendAStringToAnotherView:(NSString*)string
{
//displays the string as console output
NSLog(@"lolo%@", [NSString stringWithFormat:@"%@",string]); // i want to show values here
}
Now i want to show townName in confirmController from mapView. But it shows null. but in mapView if i use string in place of townName it shows here in confirmController.
You have to create necessary variable in appDelegate and set its property in .h and Synthesize in .m file. now you can set value for this variable in your first class and get value to destination class using appDalegate variable