views:

172

answers:

1

MainViewController.h

@class EventViewController;
@class MainViewController;

@interface MainViewController : UIViewController {
    EventViewController *eventViewController;
    MainViewController *mainViewController;
    //extern int i;
@public
    NSString *titlegame;
}

@property (retain,nonatomic) EventViewController *eventViewController;
@property (retain,nonatomic) MainViewController *mainViewController;
@property (retain,nonatomic)IBOutlet NSString *titlegame;

@end

MainViewController.m

-(IBAction)buttonClick:(id)sender{
    titlegame = [sender titleForState: UIControlStateNormal];
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"You selecet!!!!"
                                                   message:titlegame
                                                  delegate:nil
                                         cancelButtonTitle:@"OK"
                                         otherButtonTitles:nil];

    [alert show];
    //[titlegame release];
    [alert release];

    ////////
    if([titlegame isEqualToString: @"FootBall"]==YES)
        NSLog( @"Equal");
    else
        NSLog( @"NotEqual");
    EventViewController *eventController = [[EventViewController alloc]
                                           initWithNibName: @"EventView"
                                                    bundle:nil];
    self.eventViewController = eventController;
    [eventController release];

    [[self mainViewController] dismissModalViewControllerAnimated:YES];
    [eventViewController.view removeFromSuperview];
    [self.view addSubview: eventController.view];

    // eventController.labelgame.text = titlegame;
    eventViewController.labelgame.text =titlegame;
    NSLog(@"title==>%@",eventController.labelgame.text);
    NSLog(@"title1==>%@",eventViewController.labelgame.text);
    [eventViewController.labelgame retain];
}

it works properly

but in EventViewController's ViewDidLoad method i cant that label's value..

EventViewController.m:

- (void)viewDidLoad {
    NSLog(@"titlegame==>%@",labelgame.text);
}

EventWiseViewController.m:

-(IBAction)BackPressed :(id) sender
{
    EventViewController *eventController = [[EventViewController alloc]
                                           initWithNibName: @"EventView"
                                                    bundle:nil];
    self.eventWiseViewController = eventController;
    [eventController release];

    [[self eventWiseViewController] dismissModalViewControllerAnimated:YES];
    [eventViewController.view removeFromSuperview];
    [self.view addSubview: eventController.view];

    NSLog(@"final=---->%@",eventController.game1);
    eventController.labelgame.text = mainViewController.titlegame;
    NSLog(@"gmename1 ==>%@", [mainViewController titlegame]);
    NSLog(@"gamename2 ==>%@", mainViewController.titlegame);

    //NSLog(@"gmename1 ==>%@",eventController.labelgame.text);
    //NSLog(@"gmename2 ==>%@",eventController.game1);
}

but here when i go back to EventViewController the label get blank ,why?? plz tell me..

A: 

I believe you need to use something like this to access the titlegame field from a different controller

[AppDelegate sharedDelegate].mainViewController.titlegame;

This may not be exactly correct. But I think the problem you are having is related to this concept.

Joe Cannatti
thanks for help. But can you plz give me proper code becouse i am new in objective c and iphone so plz help me..
I believe that is correct. Just replace AppDelegate with the name of your appDelegate. Let me know what happens.
Joe Cannatti