Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.98 KB | None | 0 0
  1. @property(nonatomic) BOOL *isSomethingEnabled;
  2.  
  3. #import "ViewControllerB.h"
  4.  
  5. ViewControllerB *viewControllerB = [[ViewControllerB alloc] initWithNib:@"ViewControllerB" bundle:nil];
  6. viewControllerB.isSomethingEnabled = YES;
  7. [self pushViewController:viewControllerB animated:YES];
  8.  
  9. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  10.  
  11. @property(nonatomic) BOOL *isSomethingEnabled;
  12.  
  13. #import "ViewControllerB.h"
  14.  
  15. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
  16. if([segue.identifier isEqualToString:@"showDetailSegue"]){
  17. ViewControllerB *controller = (ViewControllerB *)segue.destinationViewController;
  18. controller.isSomethingEnabled = YES;
  19. }
  20. }
  21.  
  22. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
  23. if([segue.identifier isEqualToString:@"showDetailSegue"]){
  24. UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
  25. ViewControllerB *controller = (ViewControllerB *)navController.topViewController;
  26. controller.isSomethingEnabled = YES;
  27. }
  28. }
  29.  
  30. @class ViewControllerB;
  31.  
  32. @protocol ViewControllerBDelegate <NSObject>
  33. - (void)addItemViewController:(ViewControllerB *)controller didFinishEnteringItem:(NSString *)item;
  34. @end
  35.  
  36. @property (nonatomic, weak) id <ViewControllerBDelegate> delegate;
  37.  
  38. NSString *itemToPassBack = @"Pass this value back to ViewControllerA";
  39. [self.delegate addItemViewController:self didFinishEnteringItem:itemToPassBack];
  40.  
  41. #import "ViewControllerB.h"
  42.  
  43. @interface ViewControllerA : UIViewController <ViewControllerBDelegate>
  44.  
  45. - (void)addItemViewController:(ViewControllerB *)controller didFinishEnteringItem:(NSString *)item
  46. {
  47. NSLog(@"This was returned from ViewControllerB %@",item);
  48. }
  49.  
  50. ViewControllerB *viewControllerB = [[ViewControllerB alloc] initWithNib:@"ViewControllerB" bundle:nil];
  51. viewControllerB.delegate = self
  52. [[self navigationController] pushViewController:viewControllerB animated:YES];
  53.  
  54. - (void)pushToController2 {
  55.  
  56. Controller2 *obj = [[Controller2 alloc] initWithNib:@"Controller2" bundle:nil];
  57. [obj passValue:@"String"];
  58. [self pushViewController:obj animated:YES];
  59. }
  60.  
  61. @interface Controller2 : NSObject
  62.  
  63. @property (nonatomic , strong) NSString* stringPassed;
  64.  
  65. @end
  66.  
  67. @implementation Controller2
  68.  
  69. @synthesize stringPassed = _stringPassed;
  70.  
  71. - (void) passValue:(NSString *)value {
  72.  
  73. _stringPassed = value; //or self.stringPassed = value
  74. }
  75.  
  76. @end
  77.  
  78. - (void)pushToController2 {
  79.  
  80. Controller2 *obj = [[Controller2 alloc] initWithNib:@"Controller2" bundle:nil];
  81. [obj setStringPassed:@"String"];
  82. [self pushViewController:obj animated:YES];
  83. }
  84.  
  85. Controller2 *obj = [[Controller2 alloc] initWithNib:@"Controller2" bundle:nil];
  86. [obj passValue:@“String1” andValues:objArray withDate:date];
  87.  
  88. ModelClass *modelObject = [[ModelClass alloc] init];
  89. modelObject.property1 = _property1;
  90. modelObject.property2 = _property2;
  91. modelObject.property3 = _property3;
  92.  
  93. Controller2 *obj = [[Controller2 alloc] initWithNib:@"Controller2" bundle:nil];
  94. [obj passmodel: modelObject];
  95.  
  96. 1) set the private variables of the second class initialise the values by calling a custom function and passing the values.
  97. 2) setProperties do it by directlyInitialising it using the setter method.
  98. 3) pass more that 3-4 values related to each other in some manner , then create a model class and set values to its object and pass the object using any of the above process.
  99.  
  100. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  101. {
  102. if ([segue.destinationViewController isKindOfClass:[BViewController class]])
  103. {
  104. BViewController *viewController = segue.destinationViewController;
  105.  
  106. viewController.callback = ^(Type1 *value1, Type2 *value2) {
  107. // optionally, close B
  108. //[self.navigationController popViewControllerAnimated:YES];
  109.  
  110. // let's do some action after with returned values
  111. action1(value1);
  112. action2(value2);
  113. };
  114.  
  115. }
  116. }
  117.  
  118. // it is important to use "copy"
  119. @property (copy) void(^callback)(Type1 *value1, Type2 *value2);
  120.  
  121. if (self.callback)
  122. self.callback(value1, value2);
  123.  
  124. [[NSUserDefaults standardUserDefaults] setValue:value forKey:key]
  125. [[NSUserDefaults standardUserDefaults] objectForKey:key]
  126.  
  127. // Prepare the destination view controller by passing it the input we want it to work on
  128. // and the results we will look at when the user has navigated back to this controller's view.
  129.  
  130. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  131. {
  132. [[segue destinationViewController]
  133.  
  134. // This parameter gives the next controller the data it works on.
  135. segueHandoffWithInput:self.dataForNextController
  136.  
  137. // This parameter allows the next controller to pass back results
  138. // by virtue of both controllers having a pointer to the same object.
  139. andResults:self.resultsFromNextController];
  140. }
  141.  
  142. // Prepare the destination view controller by passing it the input we want it to work on
  143. // and the callback when it has done its work.
  144.  
  145. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  146. {
  147. [[segue destinationViewController]
  148.  
  149. // This parameter gives the next controller the data it works on.
  150. segueHandoffWithInput:self.dataForNextController
  151.  
  152. // This parameter allows the next controller to pass back results.
  153. resultsBlock:^(id results) {
  154. // This callback could be as involved as you like.
  155. // It can use Grand Central Dispatch to have work done on another thread for example.
  156. [self setResultsFromNextController:results];
  157. }];
  158. }
  159.  
  160. @interface SecondViewController: UIviewController{
  161. NSMutableArray *myAray;
  162. CustomObject *object;
  163. }
  164.  
  165. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  166. {
  167. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  168. if (self) {
  169. // Custom initialization
  170. myAray=[[NSMutableArray alloc] init];
  171. object=[[CustomObject alloc] init];
  172. }
  173. return self;
  174. }
  175.  
  176. -(void)setMyArray:(NSArray *)_myArray;
  177. -(void)setMyObject:(CustomObject *)_myObject;
  178.  
  179. -(void)setMyArray:(NSArray *)_myArray{
  180. [myArra addObjectsFromArray:_myArray];
  181. }
  182. -(void)setMyObject:(CustomObject *)_myObject{
  183. [object setCustomObject:_myObject];
  184. }
  185.  
  186. SecondViewController *secondView= [[SecondViewController alloc] initWithNibName:@"SecondViewController " bundle:[NSBundle MainBundle]] ;
  187. [secondView setMyArray:ArrayToPass];
  188. [secondView setMyObject:objectToPass];
  189. [self.navigationController pushViewController:secondView animated:YES ];
  190.  
  191. NextViewController* destination = (NextViewController*) segue.destinationViewController;
  192. [destinationVC setDidFinishUsingBlockCallback:^(NextViewController *destinationVC)
  193. {
  194. self.blockLabel.text = destination.blockTextField.text;
  195. }];
  196.  
  197. -(IBAction)UnWindDone:(UIStoryboardSegue *)segue { }
  198.  
  199. -(IBAction)UnWindDone:(UIStoryboardSegue *)segue {
  200. NextViewController *nextViewController = segue.sourceViewController;
  201. self.unwindLabel.text = nextViewController.unwindPropertyPass;
  202. }
  203.  
  204. @optional
  205.  
  206. - (void)checkStateDidChange:(BOOL)checked;
  207.  
  208. #import "ViewController1Delegate.h"
  209.  
  210. @interface ViewController2: UIViewController<ViewController1Delegate>
  211.  
  212. - (void)checkStateDidChange:(BOOL)checked {
  213. if (checked) {
  214. // Do whatever you want here
  215. NSLog(@"Checked");
  216. }
  217. else {
  218. // Also do whatever you want here
  219. NSLog(@"Not checked");
  220. }
  221. }
  222.  
  223. @property (weak, nonatomic) id<ViewController1Delegate> delegate;
  224.  
  225. ViewController1* controller = [[NSBundle mainBundle] loadNibNamed:@"ViewController1" owner:self options:nil][0];
  226. controller.delegate = self;
  227. [self presentViewController:controller animated:YES completion:nil];
  228.  
  229. [delegate checkStateDidChange:checked]; // You pass here YES or NO based on the check state of your control
  230.  
  231. @property (nonatomic, retain) NSString *str;
  232.  
  233. @property (nonatomic, retain) NSString *str1;
  234.  
  235. - (void)viewDidLoad
  236. {
  237. str = @"text message";
  238. [super viewDidLoad];
  239. }
  240.  
  241. -(IBAction)ButtonClicked
  242. {
  243. SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
  244. secondViewController.str1 = str;
  245. [self.navigationController pushViewController:secondViewController animated:YES];
  246. }
  247.  
  248. StrFirstValue = @"first";
  249.  
  250. NSString *strValue;
  251.  
  252. @property (strong, nonatomic) NSString *strSecondValue;
  253.  
  254. @synthesize strValue;
  255.  
  256. @property (strong, nonatomic) NSString *strValue;
  257.  
  258. SecondViewController *secondView= [[SecondViewController alloc]
  259. initWithNibName:@"SecondViewController " bundle:[NSBundle MainBundle]];
  260.  
  261. [secondView setStrSecondValue:StrFirstValue];
  262.  
  263. [self.navigationController pushViewController:secondView animated:YES ];
  264.  
  265. @interface viewControllerB : UIViewController {
  266.  
  267. NSString *string;
  268. NSArray *array;
  269.  
  270. }
  271.  
  272. - (id)initWithArray:(NSArray)a andString:(NSString)s;
  273.  
  274. #import "viewControllerB.h"
  275.  
  276. @implementation viewControllerB
  277.  
  278. - (id)initWithArray:(NSArray)a andString:(NSString)s {
  279.  
  280. array = [[NSArray alloc] init];
  281. array = a;
  282.  
  283. string = [[NSString alloc] init];
  284. string = s;
  285.  
  286. }
  287.  
  288. #import "viewControllerA.h"
  289. #import "viewControllerB.h"
  290.  
  291. @implementation viewControllerA
  292.  
  293. - (void)someMethod {
  294.  
  295. someArray = [NSArray arrayWithObjects:@"One", @"Two", @"Three", nil];
  296. someString = [NSString stringWithFormat:@"Hahahahaha"];
  297.  
  298. viewControllerB *vc = [[viewControllerB alloc] initWithArray:someArray andString:someString];
  299.  
  300. [self.navigationController pushViewController:vc animated:YES];
  301. [vc release];
  302.  
  303. }
  304.  
  305. // Register activities
  306.  
  307. MCViewFactory *factory = [MCViewFactory sharedFactory];
  308.  
  309. // the following two lines are optional.
  310. [factory registerView:@"YourSectionViewController"];
  311.  
  312. MCIntent* intent = [MCIntent intentWithSectionName:@"YourSectionViewController"];
  313. [intent setAnimationStyle:UIViewAnimationOptionTransitionFlipFromLeft];
  314. [[intent savedInstanceState] setObject:@"someValue" forKey:@"yourKey"];
  315. [[intent savedInstanceState] setObject:@"anotherValue" forKey:@"anotherKey"];
  316. // ...
  317. [[MCViewModel sharedModel] setCurrentSection:intent];
  318.  
  319. -(void)onResume:(MCIntent *)intent {
  320. NSObject* someValue = [intent.savedInstanceState objectForKey:@"yourKey"];
  321. NSObject* anotherValue = [intent.savedInstanceState objectForKey:@"anotherKey"];
  322.  
  323. // ...
  324.  
  325. // ensure the following line is called, especially for MCSectionViewController
  326. [super onResume:intent];
  327. }
  328.  
  329. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  330. {
  331. [tbl_View deselectRowAtIndexPath:indexPath animated:YES];
  332. News *newsObj = [newstitleArr objectAtIndex:indexPath.row];
  333. NewsDetailViewController *newsDetailView = [[NewsDetailViewController alloc] initWithNibName:@"NewsDetailViewController" bundle:nil];
  334.  
  335. newsDetailView.newsHeadlineStr = newsObj.newsHeadline;
  336.  
  337. [self.navigationController pushViewController:newsDetailView animated:YES];
  338. }
  339.  
  340. @interface NewsDetailViewController : UIViewController
  341. @property(nonatomic,retain) NSString *newsHeadlineStr;
  342. @end
  343.  
  344. @synthesize newsHeadlineStr;
  345.  
  346. @property (strong, nonatomic) NSString *indexNumber;
  347.  
  348. NextVC *vc=[[NextVC alloc]init];
  349.  
  350. vc.indexNumber=@"123";
  351.  
  352. [self.navigationController vc animated:YES];
  353.  
  354. + (HouseholdInventoryManager*) sharedManager; {
  355. static dispatch_once_t onceQueue;
  356. static HouseholdInventoryManager* _sharedInstance;
  357.  
  358. // dispatch_once is guaranteed to only be executed once in the
  359. // lifetime of the application
  360. dispatch_once(&onceQueue, ^{
  361. _sharedInstance = [[self alloc] init];
  362. });
  363. return _sharedInstance;
  364. }
  365.  
  366. #import <Foundation/Foundation.h>
  367.  
  368. @class JGCHouseholdInventoryItem;
  369.  
  370. @interface HouseholdInventoryManager : NSObject
  371. /*!
  372. The global singleton for accessing application data
  373. */
  374. + (HouseholdInventoryManager*) sharedManager;
  375.  
  376.  
  377. - (NSArray *) entireHouseholdInventory;
  378. - (NSArray *) luxuryItems;
  379. - (NSArray *) nonInsuredItems;
  380.  
  381. - (void) addHouseholdItemToHomeInventory:(JGCHouseholdInventoryItem*)item;
  382. - (void) editHouseholdItemInHomeInventory:(JGCHouseholdInventoryItem*)item;
  383. - (void) deleteHoueholdItemFromHomeInventory:(JGCHouseholdInventoryItem*)item;
  384. @end
  385.  
  386. #import <UIKit/UIKit.h>
  387.  
  388. @interface ViewController : UIViewController
  389. {
  390. IBOutlet UITextField *mytext1,*mytext2,*mytext3,*mytext4;
  391. }
  392.  
  393. @property (nonatomic,retain) IBOutlet UITextField *mytext1,*mytext2,*mytext3,*mytext4;
  394.  
  395. -(IBAction)goToNextScreen:(id)sender;
  396.  
  397. @end
  398.  
  399. #import "ViewController.h"
  400.  
  401. #import "NewViewController.h"
  402.  
  403. @implementation ViewController
  404. @synthesize mytext1,mytext2,mytext3,mytext4;
  405.  
  406. -(IBAction)goToNextScreen:(id)sender
  407. {
  408. NSArray *arr = [NSArray arrayWithObjects:mytext1.text,mytext2.text,mytext3.text,mytext4.text, nil];
  409.  
  410.  
  411. NewViewController *newVc = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
  412.  
  413. newVc.arrayList = arr;
  414.  
  415. [self.navigationController pushViewController:newVc animated:YES];
  416.  
  417. }
  418.  
  419. #import <UIKit/UIKit.h>
  420.  
  421. @interface NewViewController : UITableViewController
  422. {
  423. NSArray *arrayList;
  424.  
  425. NSString *name,*age,*dob,*mobile;
  426.  
  427. }
  428.  
  429. @property(nonatomic, retain)NSArray *arrayList;
  430.  
  431. @end
  432.  
  433. #import "NewViewController.h"
  434.  
  435. #import "ViewController.h"
  436.  
  437. @implementation NewViewController
  438. @synthesize arrayList;
  439.  
  440. #pragma mark - Table view data source
  441.  
  442. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  443. {
  444.  
  445. // Return the number of sections.
  446. return 1;
  447. }
  448.  
  449. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  450. {
  451.  
  452. // Return the number of rows in the section.
  453. return [arrayList count];
  454. }
  455.  
  456. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  457. {
  458. static NSString *CellIdentifier = @"Cell";
  459. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  460. if (cell == nil)
  461. {
  462. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  463. }
  464. // Configure the cell...
  465. cell.textLabel.text = [arrayList objectAtIndex:indexPath.row];
  466. return cell;
  467.  
  468.  
  469. }
  470.  
  471. @end
  472.  
  473. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  474.  
  475. //this solution is for using Core Data
  476. YourCDEntityName * value = (YourCDEntityName *)[[self fetchedResultsController] objectAtIndexPath: indexPath];
  477.  
  478. YourSecondViewController * details = [self.storyboard instantiateViewControllerWithIdentifier:@"nameOfYourSecondVC"];//make sure in storyboards you give your second VC an identifier
  479.  
  480. //Make sure you declare your value in the second view controller
  481. details.selectedValue = value;
  482.  
  483. //Now that you have said to pass value all you need to do is change views
  484. [self.navigationController pushViewController: details animated:YES];
  485.  
  486. }
  487.  
  488. override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
  489. var next = segue.destinationViewController as NextViewController
  490. next.dataSource = dataSource
  491. }
  492.  
  493. func viewDidLoad() {
  494. super.viewDidLoad()
  495. var data = dataAccess.requestData()
  496. }
  497.  
  498. let notebookName = note.notebook.name
  499.  
  500. #import "ViewControllerB.h"
  501.  
  502. ViewControllerB *viewControllerB = [[ViewControllerB alloc] initWithNib:@"ViewControllerB" bundle:nil];
  503. viewControllerB.isSomethingEnabled = YES;
  504. [self pushViewController:viewControllerB animated:YES];
  505.  
  506. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  507. So to pass a BOOL from ViewControllerA to ViewControllerB we would do the following:
  508.  
  509. @property(nonatomic) BOOL *isSomethingEnabled;
  510.  
  511. #import "ViewControllerB.h"
  512.  
  513. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
  514. if([segue.identifier isEqualToString:@"showDetailSegue"]){
  515. ViewControllerB *controller = (ViewControllerB *)segue.destinationViewController;
  516. controller.isSomethingEnabled = YES;
  517. }
  518. }
  519.  
  520. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
  521. if([segue.identifier isEqualToString:@"showDetailSegue"]){
  522. UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
  523. ViewControllerB *controller = (ViewControllerB *)navController.topViewController;
  524. controller.isSomethingEnabled = YES;
  525. }
  526. }
  527.  
  528. @class ViewControllerB;
  529.  
  530. @protocol ViewControllerBDelegate <NSObject>
  531. - (void)addItemViewController:(ViewControllerB *)controller didFinishEnteringItem:(NSString *)item;
  532. @end
  533. next still in the ViewControllerB.h you need to setup a delegate property and synthesize in ViewControllerB.m
  534.  
  535. @property (nonatomic, weak) id <ViewControllerBDelegate> delegate;
  536. In ViewControllerB we call a message on the delegate when we pop the view controller.
  537.  
  538. NSString *itemToPassBack = @"Pass this value back to ViewControllerA";
  539. [self.delegate addItemViewController:self didFinishEnteringItem:itemToPassBack];
  540. That's it for ViewControllerB. Now in ViewControllerA.h, tell ViewControllerA to import ViewControllerB and conform to its protocol.
  541.  
  542. #import "ViewControllerB.h"
  543.  
  544. @interface ViewControllerA : UIViewController <ViewControllerBDelegate>
  545. In ViewControllerA.m implement the following method from our protocol
  546.  
  547. - (void)addItemViewController:(ViewControllerB *)controller didFinishEnteringItem:(NSString *)item
  548. {
  549. NSLog(@"This was returned from ViewControllerB %@",item);
  550. }
  551. The last thing we need to do is tell ViewControllerB that ViewControllerA is its delegate before we push ViewControllerB on to nav stack.
  552.  
  553. ViewControllerB *viewControllerB = [[ViewControllerB alloc] initWithNib:@"ViewControllerB" bundle:nil];
  554. viewControllerB.delegate = self
  555. [[self navigationController] pushViewController:viewControllerB animated:YES];
  556.  
  557. var data: AnyObject?
  558. {
  559. get
  560. {
  561. return NSUserDefaults.standardUserDefaults().objectForKey("data")
  562. }
  563. set
  564. {
  565. NSUserDefaults.standardUserDefaults().setObject(newValue!, forKey: "data")
  566. NSUserDefaults.standardUserDefaults().synchronize()
  567. }
  568. }
  569.  
  570. // String Example:
  571. data = "Masterfego"
  572.  
  573. @IBOutlet weak var label: UILabel!
  574.  
  575. var data: AnyObject?
  576. {
  577. get
  578. {
  579. return NSUserDefaults.standardUserDefaults().objectForKey("data")
  580. }
  581.  
  582. }
  583.  
  584. // label example
  585. label.text = data as String // your label will show "Masterfego"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement