Advertisement
ilis

sharing_data_between_Classes

Jun 22nd, 2012
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ----------------------
  2. //yourAppDelegate.h
  3. @interface yourAppDelegate : UIResponder <UIApplicationDelegate>
  4. //i assume you want to share a string
  5. @property (copy, readwrite) NSString  *sharedString;
  6. @end
  7. ----------------------
  8. //yourAppDelegate.m
  9. @synthesize sharedString;
  10. ...
  11. -------------------------
  12.  
  13.  
  14. ----------------------
  15. classA.m(the source where you get the string data from xml)
  16. //on the top of file import your appDelegate class
  17. #import "YourAppDelegate.h"
  18. .
  19. .
  20. //navigate to the place(place) you want to share data, i assume you do that in viewDidLoad
  21. - (void)viewDidLoad
  22. {
  23. .
  24. .
  25. .
  26. //your other codes...
  27. //i assume your parsed string(which you want to share) is an NSString called myString;
  28. NSLog("Result from Server: %@", myString);
  29.  YourAppDelegate   *sharedData = (YourAppDelegate *)([[UIApplication sharedApplication]delegate]);
  30. sharedData.sharedString= myString;
  31. }
  32. -------------------------------------
  33. ------------------------------------
  34. //ClassB.m
  35. //in your classB, again import your AppDelegate,
  36. .
  37. .
  38. //navigate to the method you want to retrieve shared data
  39. YourAppDelegate   *sharedData = (YourAppDelegate *)([[UIApplication sharedApplication]delegate]);
  40. NSString *myNewString =sharedData.myString;
  41. .......
  42. .
  43. .
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement