Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

How to call from one UIViewController another UIViewController

KaraM84KaraM84 Posts: 4New Users
edited June 2011 in iPhone SDK Development
Hi im normaly a java developer and im new in Objective C

I have two ViewController

- FirstViewController
- SecondViewController

my FirstViewController has a boolean value which is initialized.
Now i want call the initialized boolean from my SecondViewController.
Any information or tutorials how i can do this?
Post edited by KaraM84 on

Replies

  • ngaikwadngaikwad IndiaPosts: 496Registered Users @ @
    edited June 2011
    use share this data [which you want to send to next view] variable in application
    <font face="Arial Narrow">Thank & Regard</font><br />
    NI3(Not Impossible 3)
  • KaraM84KaraM84 Posts: 4New Users
    edited June 2011
    ngaikwad wrote: »
    use share this data [which you want to send to next view] variable in application


    Hi,
    have you any examples?

    If i call

    FirstViewController *vController = [[FirstViewController alloc] initWithNibName:nil bundle:nil];

    then i get an new Object of the FirstViewController and dont get the boolean value which was initialized.
  • dany_devdany_dev Posts: 4,696Tutorial Authors, Registered Users @ @ @ @ @
    edited June 2011
    Suppose you have in FirstViewController that bool value (we can call it boolA), then you need to create a boolean on your SecondViewController (we can call it boolB) and fill it when you load the 2nd view controller.

    somewhere on your code you have something like
    -(void)openOtherViewController{
    
        SecondViewController *sec = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
        [B]sec.boolB = boolA;[/B]
        [self presentModalViewController:sec animated:YES];
        [sec release];
    }
    
  • ngaikwadngaikwad IndiaPosts: 496Registered Users @ @
    edited June 2011
    <font face="Arial Narrow">Thank & Regard</font><br />
    NI3(Not Impossible 3)
  • KaraM84KaraM84 Posts: 4New Users
    edited June 2011
    dany_dev wrote: »
    Suppose you have in FirstViewController that bool value (we can call it boolA), then you need to create a boolean on your SecondViewController (we can call it boolB) and fill it when you load the 2nd view controller.


    Hi,
    i did your example but i dont get the result that i want

    The Logs
    2011-06-13 21:18:12.105 GPFace2[231:207] First log of Boolean is: 0
    2011-06-13 21:18:12.106 GPFace2[231:207] Second log of Boolean is: 1
    2011-06-13 21:18:18.035 GPFace2[231:207] Third log of Boolean is: 0
    
    - (void)viewDidLoad {
       // [super viewDidLoad];
    	FirstViewController *vController = [[FirstViewController alloc] initWithNibName:@"FirstView" bundle:nil];
    	NSLog(@"First log of Boolean is: %d",vController.myBoolean);
    	vController.myBoolean = YES;
    	NSLog(@"Second log of Boolean is: %d",vController.myBoolean);	
    }
    

    then i have a Button which i click
    - (IBAction)goToMapView{
    	FirstViewController *vController = [[FirstViewController alloc] initWithNibName:@"FirstView" bundle:nil];
    	[self presentModalViewController:vController animated:YES];
    	NSLog(@"Third log of Boolean is: %d",vController.myBoolean);
    	[vController release];
    }
    



    I thought the third log must be 1. What do i wrong?
    Thx for help
  • dany_devdany_dev Posts: 4,696Tutorial Authors, Registered Users @ @ @ @ @
    edited June 2011
    you supposed bad, and mean that you not really understand what Object Oriented mean....


    every time you alloc\init something, mean that is a NEW istance (so you can't see all the "old" things done in another istance of that Class).

    And however I said to use in another mode.....


    FirstViewController.m
    - (void)viewDidLoad {
            [super viewDidLoad];
    	
    	myBoolean = YES;
    
    }
    
    - (IBAction)goToMapView{
    	SecondViewController *sec = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
        sec.boolB = myBoolean;
        [self presentModalViewController:sec animated:YES];
        [sec release];
    }
    

    SecondViewController.m
    - (void)viewDidLoad {
            [super viewDidLoad];
    	
    	NSLog(@"Boolean of SecViewCon is: %d",boolB);	
    }
    
    

    The output will be "Boolean of SecViewCon is: 1"
  • KaraM84KaraM84 Posts: 4New Users
    edited June 2011
    Hi dany,
    now i understand how it works.
    Thx
Sign In or Register to comment.