Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 1.73 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Passing Parameter From a View Back To another View's UITableView's Cell
  2. @interface Smoke_ApplicationAppDelegate : NSObject {
  3.  
  4.   UIWindow *window;
  5.   UINavigationController *navigationController;
  6.   NSString *messageString;  //This would be your String Variable
  7. }
  8.  @property(nonatomic,retain)NSString *messageString;
  9.        
  10. @implementation Smoke_ApplicationAppDelegate
  11.  
  12. @synthesize window;
  13. @synthesize navigationController;
  14. @synthesize messageString; // Synthesize it over here..
  15.        
  16. import "DelegateFile.h"
  17.  
  18. @implementation About
  19.  
  20. DelegateFile *appDel;
  21.        
  22. -(void)viewDidLoad { [super viewDidLoad];
  23.  
  24. appDel=[[UIApplication sharedApplication]delegate];
  25.  
  26. }
  27.        
  28. appDel.messageString
  29.        
  30. @protocol SecondViewControllerDelegate
  31. - (void) viewControllerWillDisappearWithLabelText: (NSString*)text;
  32. @end
  33.        
  34. //in the .h file
  35. @interface SecondViewController : UIViewController {
  36.     //declare instance variables
  37. }
  38. @property(nonatomic, assign) id<SecondViewControllerDelegate> delegate;
  39. @end
  40.  
  41. //in the .m file
  42. @implementation SecondViewController
  43.  
  44. @synthesize delegate;
  45.  
  46. //[code...]
  47. @end
  48.        
  49. //in the .h file
  50. @interface FirstViewController : UIViewController<SecondViewControllerDelegate> {
  51.     //[instance variables]
  52. }
  53. //[methods and properties]
  54. @end
  55.  
  56. //in the .m file
  57. @implementation FirstViewController
  58. //[code...]
  59.  
  60. - (void) viewControllerWillDisappearWithLabelText: (NSString*)text {
  61.     //do whatever you need to do with the text
  62. }
  63.  
  64. //[code...]
  65. @end
  66.        
  67. SecondViewController* sv = [[SecondViewController alloc] init];
  68. sv.somestring = someanotherstring;
  69. sv.delegate = self;
  70.        
  71. - (void) viewWillDisappear: (bool)animated {
  72.     [super viewWillDisappear:animated];
  73.     if (self.delegate) {
  74.         [self.delegate viewControllerWillDisappearWithLabelText: myLabel.text];
  75.     }
  76. }