Why Won't My View Load Correctly

Discussion in 'iOS Programming' started by talguy, Jul 1, 2009.

  1. talguy macrumors member

    Jun 17, 2009
    Hey all,

    I am trying objcetive-c and iphone sdk so I am creating a navigation app that has a list of people w/ pictures. When I click on the view button it loads up the next view and should pass along the picture and name of the person. The second view loads up fine but done not pass along the picture or name. Could anyone help to figure this out.

    here is the code that handles the button pressed event.

    - (IBAction)buttonPressed:(id)sender {
    	PeopleDetailsViewController *detailView = [[PeopleDetailsViewController alloc] initWithNibName:@"PeopleDetailView" bundle:nil];
    	[detailView setDetails:PersonOneImage.image name:@"John Doe" status:@"On the train"];
    	[self.navigationController pushViewController:detailView animated:YES];
    	[detailView release];
    here is the setDetails method code.

    @interface PeopleDetailsViewController : UIViewController {
    	IBOutlet UIImageView *personImage;
    	IBOutlet UILabel *personName;
    	IBOutlet UILabel *personStatus;
    - (void)setDetails:(UIImage *)personPic name:(NSString *)Name status:(NSString *)Status;
    - (void)setDetails:(UIImage *)personPic name:(NSString *)Name status:(NSString *)Status {
    	personImage = [[UIImageView alloc] initWithImage:personPic];
    	personName.text = Name;
    	personStatus.text = Status;
    	NSLog(@"Person's name is: \"%@\" and their status is: \"%@\"", Name, Status);
    	NSLog(@"The Name Label is:%@", personName.text);

    the first log in the setDetails function returns the right value but the second log returns null.

    Thanks in advance
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    The view controller's view isn't loaded until after its pushed. So at the time when you are setting the details the outlets aren't yet set. They are still nil at that point.

    What you should do is have ivars and properties for the details values. Save them inside setDetails. Then in viewDidLoad set the properties of the outlets from these ivars.
  3. talguy thread starter macrumors member

    Jun 17, 2009
    Ok i'll try that. I'm new to this stuff and still confused by it.

    It worked thanks a lot

Share This Page