views:

85

answers:

1

I am trying to load a UIView with multiple data. The problem is data is not displays in first load but loads it in subsequent clicks. Can you help me trace the problem.

FirstViewController.h

    #import <UIKit/UIKit.h>

    @class SecondViewController;

    @interface FirstViewController : UIViewController {

        IBOutlet SecondViewController *mySecondViewController;
        IBOutlet UIImageView *myimage1;
        IBOutlet UIImageView *myimage2;
        IBOutlet UILabel *mylabel1;
        IBOutlet UILabel *mylabel2;

    }

    @property (nonatomic, retain) IBOutlet SecondViewController *mySecondViewController;
    @property (nonatomic, retain) IBOutlet UIImageView *myimage1;
    @property (nonatomic, retain) IBOutlet UIImageView *myimage2;
    @property (nonatomic, retain) IBOutlet UILabel *mylabel1;
    @property (nonatomic, retain) IBOutlet UILabel *mylabel2;

    - (IBAction)bringNextView:(id)sender;
    - (IBAction)bringNextView2: (id)sender;

    @end

    FirstViewController.m

        #import "FirstViewController.h"
        #import "SecondViewController.h"
        @implementation FirstViewController
        @synthesize mySecondViewController,myimage1, myimage2, mylabel1, mylabel2;
        - (IBAction)bringNextView:(id)sender {
         mySecondViewController.name.text = @"Paul";
         mySecondViewController.myimageview.image = [UIImage imageNamed:@"Paul.png"];
         mySecondViewController.statmsg.text = @"Doing iPhone Development";
         [[self navigationController] pushViewController:mySecondViewController animated:YES]; 
        }


    SecondViewController.m

    #import "SecondViewController.h"
    @implementation SecondViewController
    @synthesize myimageview, name, statmsg
    - (void)viewDidLoad {
        [self setTitle:@"Details"];
        [super viewDidLoad];
    }

Properties are not coming for the first time. But are displays after returning from view and then loading view again.

I am loading SecondViewController from FirstViewController.

A: 

Hi I have solved this. Actually I was pushing my view controller after setting up the property and that caused this issue.

Instead of :

mySecondViewController.name.text = @"Paul";
mySecondViewController.myimageview.image = [UIImage imageNamed:@"Paul.png"];
mySecondViewController.statmsg.text = @"Doing iPhone Development";
[[self navigationController] pushViewController:mySecondViewController animated:YES];

It should be :

[[self navigationController] pushViewController:mySecondViewController animated:YES];
mySecondViewController.name.text = @"Paul";
mySecondViewController.myimageview.image = [UIImage imageNamed:@"Paul.png"];
mySecondViewController.statmsg.text = @"Doing iPhone Development";
Harrydeo
The first way is the way I've always done this, and it should work. You have something else wrong.
Kendall Helmstetter Gelner
any pointers on what could be the problem? As far as I can tell NIB files may not have loaded the property in first example.
Harrydeo