Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @property(nonatomic) BOOL *isSomethingEnabled;
- #import "ViewControllerB.h"
- ViewControllerB *viewControllerB = [[ViewControllerB alloc] initWithNib:@"ViewControllerB" bundle:nil];
- viewControllerB.isSomethingEnabled = YES;
- [self pushViewController:viewControllerB animated:YES];
- -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
- @property(nonatomic) BOOL *isSomethingEnabled;
- #import "ViewControllerB.h"
- -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
- if([segue.identifier isEqualToString:@"showDetailSegue"]){
- ViewControllerB *controller = (ViewControllerB *)segue.destinationViewController;
- controller.isSomethingEnabled = YES;
- }
- }
- -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
- if([segue.identifier isEqualToString:@"showDetailSegue"]){
- UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
- ViewControllerB *controller = (ViewControllerB *)navController.topViewController;
- controller.isSomethingEnabled = YES;
- }
- }
- @class ViewControllerB;
- @protocol ViewControllerBDelegate <NSObject>
- - (void)addItemViewController:(ViewControllerB *)controller didFinishEnteringItem:(NSString *)item;
- @end
- @property (nonatomic, weak) id <ViewControllerBDelegate> delegate;
- NSString *itemToPassBack = @"Pass this value back to ViewControllerA";
- [self.delegate addItemViewController:self didFinishEnteringItem:itemToPassBack];
- #import "ViewControllerB.h"
- @interface ViewControllerA : UIViewController <ViewControllerBDelegate>
- - (void)addItemViewController:(ViewControllerB *)controller didFinishEnteringItem:(NSString *)item
- {
- NSLog(@"This was returned from ViewControllerB %@",item);
- }
- ViewControllerB *viewControllerB = [[ViewControllerB alloc] initWithNib:@"ViewControllerB" bundle:nil];
- viewControllerB.delegate = self
- [[self navigationController] pushViewController:viewControllerB animated:YES];
- - (void)pushToController2 {
- Controller2 *obj = [[Controller2 alloc] initWithNib:@"Controller2" bundle:nil];
- [obj passValue:@"String"];
- [self pushViewController:obj animated:YES];
- }
- @interface Controller2 : NSObject
- @property (nonatomic , strong) NSString* stringPassed;
- @end
- @implementation Controller2
- @synthesize stringPassed = _stringPassed;
- - (void) passValue:(NSString *)value {
- _stringPassed = value; //or self.stringPassed = value
- }
- @end
- - (void)pushToController2 {
- Controller2 *obj = [[Controller2 alloc] initWithNib:@"Controller2" bundle:nil];
- [obj setStringPassed:@"String"];
- [self pushViewController:obj animated:YES];
- }
- Controller2 *obj = [[Controller2 alloc] initWithNib:@"Controller2" bundle:nil];
- [obj passValue:@“String1” andValues:objArray withDate:date];
- ModelClass *modelObject = [[ModelClass alloc] init];
- modelObject.property1 = _property1;
- modelObject.property2 = _property2;
- modelObject.property3 = _property3;
- Controller2 *obj = [[Controller2 alloc] initWithNib:@"Controller2" bundle:nil];
- [obj passmodel: modelObject];
- 1) set the private variables of the second class initialise the values by calling a custom function and passing the values.
- 2) setProperties do it by directlyInitialising it using the setter method.
- 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.
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
- {
- if ([segue.destinationViewController isKindOfClass:[BViewController class]])
- {
- BViewController *viewController = segue.destinationViewController;
- viewController.callback = ^(Type1 *value1, Type2 *value2) {
- // optionally, close B
- //[self.navigationController popViewControllerAnimated:YES];
- // let's do some action after with returned values
- action1(value1);
- action2(value2);
- };
- }
- }
- // it is important to use "copy"
- @property (copy) void(^callback)(Type1 *value1, Type2 *value2);
- if (self.callback)
- self.callback(value1, value2);
- [[NSUserDefaults standardUserDefaults] setValue:value forKey:key]
- [[NSUserDefaults standardUserDefaults] objectForKey:key]
- // Prepare the destination view controller by passing it the input we want it to work on
- // and the results we will look at when the user has navigated back to this controller's view.
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
- {
- [[segue destinationViewController]
- // This parameter gives the next controller the data it works on.
- segueHandoffWithInput:self.dataForNextController
- // This parameter allows the next controller to pass back results
- // by virtue of both controllers having a pointer to the same object.
- andResults:self.resultsFromNextController];
- }
- // Prepare the destination view controller by passing it the input we want it to work on
- // and the callback when it has done its work.
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
- {
- [[segue destinationViewController]
- // This parameter gives the next controller the data it works on.
- segueHandoffWithInput:self.dataForNextController
- // This parameter allows the next controller to pass back results.
- resultsBlock:^(id results) {
- // This callback could be as involved as you like.
- // It can use Grand Central Dispatch to have work done on another thread for example.
- [self setResultsFromNextController:results];
- }];
- }
- @interface SecondViewController: UIviewController{
- NSMutableArray *myAray;
- CustomObject *object;
- }
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- myAray=[[NSMutableArray alloc] init];
- object=[[CustomObject alloc] init];
- }
- return self;
- }
- -(void)setMyArray:(NSArray *)_myArray;
- -(void)setMyObject:(CustomObject *)_myObject;
- -(void)setMyArray:(NSArray *)_myArray{
- [myArra addObjectsFromArray:_myArray];
- }
- -(void)setMyObject:(CustomObject *)_myObject{
- [object setCustomObject:_myObject];
- }
- SecondViewController *secondView= [[SecondViewController alloc] initWithNibName:@"SecondViewController " bundle:[NSBundle MainBundle]] ;
- [secondView setMyArray:ArrayToPass];
- [secondView setMyObject:objectToPass];
- [self.navigationController pushViewController:secondView animated:YES ];
- NextViewController* destination = (NextViewController*) segue.destinationViewController;
- [destinationVC setDidFinishUsingBlockCallback:^(NextViewController *destinationVC)
- {
- self.blockLabel.text = destination.blockTextField.text;
- }];
- -(IBAction)UnWindDone:(UIStoryboardSegue *)segue { }
- -(IBAction)UnWindDone:(UIStoryboardSegue *)segue {
- NextViewController *nextViewController = segue.sourceViewController;
- self.unwindLabel.text = nextViewController.unwindPropertyPass;
- }
- @optional
- - (void)checkStateDidChange:(BOOL)checked;
- #import "ViewController1Delegate.h"
- @interface ViewController2: UIViewController<ViewController1Delegate>
- - (void)checkStateDidChange:(BOOL)checked {
- if (checked) {
- // Do whatever you want here
- NSLog(@"Checked");
- }
- else {
- // Also do whatever you want here
- NSLog(@"Not checked");
- }
- }
- @property (weak, nonatomic) id<ViewController1Delegate> delegate;
- ViewController1* controller = [[NSBundle mainBundle] loadNibNamed:@"ViewController1" owner:self options:nil][0];
- controller.delegate = self;
- [self presentViewController:controller animated:YES completion:nil];
- [delegate checkStateDidChange:checked]; // You pass here YES or NO based on the check state of your control
- @property (nonatomic, retain) NSString *str;
- @property (nonatomic, retain) NSString *str1;
- - (void)viewDidLoad
- {
- str = @"text message";
- [super viewDidLoad];
- }
- -(IBAction)ButtonClicked
- {
- SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
- secondViewController.str1 = str;
- [self.navigationController pushViewController:secondViewController animated:YES];
- }
- StrFirstValue = @"first";
- NSString *strValue;
- @property (strong, nonatomic) NSString *strSecondValue;
- @synthesize strValue;
- @property (strong, nonatomic) NSString *strValue;
- SecondViewController *secondView= [[SecondViewController alloc]
- initWithNibName:@"SecondViewController " bundle:[NSBundle MainBundle]];
- [secondView setStrSecondValue:StrFirstValue];
- [self.navigationController pushViewController:secondView animated:YES ];
- @interface viewControllerB : UIViewController {
- NSString *string;
- NSArray *array;
- }
- - (id)initWithArray:(NSArray)a andString:(NSString)s;
- #import "viewControllerB.h"
- @implementation viewControllerB
- - (id)initWithArray:(NSArray)a andString:(NSString)s {
- array = [[NSArray alloc] init];
- array = a;
- string = [[NSString alloc] init];
- string = s;
- }
- #import "viewControllerA.h"
- #import "viewControllerB.h"
- @implementation viewControllerA
- - (void)someMethod {
- someArray = [NSArray arrayWithObjects:@"One", @"Two", @"Three", nil];
- someString = [NSString stringWithFormat:@"Hahahahaha"];
- viewControllerB *vc = [[viewControllerB alloc] initWithArray:someArray andString:someString];
- [self.navigationController pushViewController:vc animated:YES];
- [vc release];
- }
- // Register activities
- MCViewFactory *factory = [MCViewFactory sharedFactory];
- // the following two lines are optional.
- [factory registerView:@"YourSectionViewController"];
- MCIntent* intent = [MCIntent intentWithSectionName:@"YourSectionViewController"];
- [intent setAnimationStyle:UIViewAnimationOptionTransitionFlipFromLeft];
- [[intent savedInstanceState] setObject:@"someValue" forKey:@"yourKey"];
- [[intent savedInstanceState] setObject:@"anotherValue" forKey:@"anotherKey"];
- // ...
- [[MCViewModel sharedModel] setCurrentSection:intent];
- -(void)onResume:(MCIntent *)intent {
- NSObject* someValue = [intent.savedInstanceState objectForKey:@"yourKey"];
- NSObject* anotherValue = [intent.savedInstanceState objectForKey:@"anotherKey"];
- // ...
- // ensure the following line is called, especially for MCSectionViewController
- [super onResume:intent];
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- [tbl_View deselectRowAtIndexPath:indexPath animated:YES];
- News *newsObj = [newstitleArr objectAtIndex:indexPath.row];
- NewsDetailViewController *newsDetailView = [[NewsDetailViewController alloc] initWithNibName:@"NewsDetailViewController" bundle:nil];
- newsDetailView.newsHeadlineStr = newsObj.newsHeadline;
- [self.navigationController pushViewController:newsDetailView animated:YES];
- }
- @interface NewsDetailViewController : UIViewController
- @property(nonatomic,retain) NSString *newsHeadlineStr;
- @end
- @synthesize newsHeadlineStr;
- @property (strong, nonatomic) NSString *indexNumber;
- NextVC *vc=[[NextVC alloc]init];
- vc.indexNumber=@"123";
- [self.navigationController vc animated:YES];
- + (HouseholdInventoryManager*) sharedManager; {
- static dispatch_once_t onceQueue;
- static HouseholdInventoryManager* _sharedInstance;
- // dispatch_once is guaranteed to only be executed once in the
- // lifetime of the application
- dispatch_once(&onceQueue, ^{
- _sharedInstance = [[self alloc] init];
- });
- return _sharedInstance;
- }
- #import <Foundation/Foundation.h>
- @class JGCHouseholdInventoryItem;
- @interface HouseholdInventoryManager : NSObject
- /*!
- The global singleton for accessing application data
- */
- + (HouseholdInventoryManager*) sharedManager;
- - (NSArray *) entireHouseholdInventory;
- - (NSArray *) luxuryItems;
- - (NSArray *) nonInsuredItems;
- - (void) addHouseholdItemToHomeInventory:(JGCHouseholdInventoryItem*)item;
- - (void) editHouseholdItemInHomeInventory:(JGCHouseholdInventoryItem*)item;
- - (void) deleteHoueholdItemFromHomeInventory:(JGCHouseholdInventoryItem*)item;
- @end
- #import <UIKit/UIKit.h>
- @interface ViewController : UIViewController
- {
- IBOutlet UITextField *mytext1,*mytext2,*mytext3,*mytext4;
- }
- @property (nonatomic,retain) IBOutlet UITextField *mytext1,*mytext2,*mytext3,*mytext4;
- -(IBAction)goToNextScreen:(id)sender;
- @end
- #import "ViewController.h"
- #import "NewViewController.h"
- @implementation ViewController
- @synthesize mytext1,mytext2,mytext3,mytext4;
- -(IBAction)goToNextScreen:(id)sender
- {
- NSArray *arr = [NSArray arrayWithObjects:mytext1.text,mytext2.text,mytext3.text,mytext4.text, nil];
- NewViewController *newVc = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
- newVc.arrayList = arr;
- [self.navigationController pushViewController:newVc animated:YES];
- }
- #import <UIKit/UIKit.h>
- @interface NewViewController : UITableViewController
- {
- NSArray *arrayList;
- NSString *name,*age,*dob,*mobile;
- }
- @property(nonatomic, retain)NSArray *arrayList;
- @end
- #import "NewViewController.h"
- #import "ViewController.h"
- @implementation NewViewController
- @synthesize arrayList;
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- // Return the number of sections.
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- // Return the number of rows in the section.
- return [arrayList count];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil)
- {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
- }
- // Configure the cell...
- cell.textLabel.text = [arrayList objectAtIndex:indexPath.row];
- return cell;
- }
- @end
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- //this solution is for using Core Data
- YourCDEntityName * value = (YourCDEntityName *)[[self fetchedResultsController] objectAtIndexPath: indexPath];
- YourSecondViewController * details = [self.storyboard instantiateViewControllerWithIdentifier:@"nameOfYourSecondVC"];//make sure in storyboards you give your second VC an identifier
- //Make sure you declare your value in the second view controller
- details.selectedValue = value;
- //Now that you have said to pass value all you need to do is change views
- [self.navigationController pushViewController: details animated:YES];
- }
- override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
- var next = segue.destinationViewController as NextViewController
- next.dataSource = dataSource
- }
- func viewDidLoad() {
- super.viewDidLoad()
- var data = dataAccess.requestData()
- }
- let notebookName = note.notebook.name
- #import "ViewControllerB.h"
- ViewControllerB *viewControllerB = [[ViewControllerB alloc] initWithNib:@"ViewControllerB" bundle:nil];
- viewControllerB.isSomethingEnabled = YES;
- [self pushViewController:viewControllerB animated:YES];
- -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
- So to pass a BOOL from ViewControllerA to ViewControllerB we would do the following:
- @property(nonatomic) BOOL *isSomethingEnabled;
- #import "ViewControllerB.h"
- -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
- if([segue.identifier isEqualToString:@"showDetailSegue"]){
- ViewControllerB *controller = (ViewControllerB *)segue.destinationViewController;
- controller.isSomethingEnabled = YES;
- }
- }
- -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
- if([segue.identifier isEqualToString:@"showDetailSegue"]){
- UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
- ViewControllerB *controller = (ViewControllerB *)navController.topViewController;
- controller.isSomethingEnabled = YES;
- }
- }
- @class ViewControllerB;
- @protocol ViewControllerBDelegate <NSObject>
- - (void)addItemViewController:(ViewControllerB *)controller didFinishEnteringItem:(NSString *)item;
- @end
- next still in the ViewControllerB.h you need to setup a delegate property and synthesize in ViewControllerB.m
- @property (nonatomic, weak) id <ViewControllerBDelegate> delegate;
- In ViewControllerB we call a message on the delegate when we pop the view controller.
- NSString *itemToPassBack = @"Pass this value back to ViewControllerA";
- [self.delegate addItemViewController:self didFinishEnteringItem:itemToPassBack];
- That's it for ViewControllerB. Now in ViewControllerA.h, tell ViewControllerA to import ViewControllerB and conform to its protocol.
- #import "ViewControllerB.h"
- @interface ViewControllerA : UIViewController <ViewControllerBDelegate>
- In ViewControllerA.m implement the following method from our protocol
- - (void)addItemViewController:(ViewControllerB *)controller didFinishEnteringItem:(NSString *)item
- {
- NSLog(@"This was returned from ViewControllerB %@",item);
- }
- The last thing we need to do is tell ViewControllerB that ViewControllerA is its delegate before we push ViewControllerB on to nav stack.
- ViewControllerB *viewControllerB = [[ViewControllerB alloc] initWithNib:@"ViewControllerB" bundle:nil];
- viewControllerB.delegate = self
- [[self navigationController] pushViewController:viewControllerB animated:YES];
- var data: AnyObject?
- {
- get
- {
- return NSUserDefaults.standardUserDefaults().objectForKey("data")
- }
- set
- {
- NSUserDefaults.standardUserDefaults().setObject(newValue!, forKey: "data")
- NSUserDefaults.standardUserDefaults().synchronize()
- }
- }
- // String Example:
- data = "Masterfego"
- @IBOutlet weak var label: UILabel!
- var data: AnyObject?
- {
- get
- {
- return NSUserDefaults.standardUserDefaults().objectForKey("data")
- }
- }
- // label example
- label.text = data as String // your label will show "Masterfego"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement