Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

talguy

macrumors member
Original poster
Jun 17, 2009
30
0
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.

Code:
- (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.

Code:
@interface PeopleDetailsViewController : UIViewController {
	IBOutlet UIImageView *personImage;
	IBOutlet UILabel *personName;
	IBOutlet UILabel *personStatus;
}

- (void)setDetails:(UIImage *)personPic name:(NSString *)Name status:(NSString *)Status;
@end

- (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
 
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.
 
Ok i'll try that. I'm new to this stuff and still confused by it.


It worked thanks a lot
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.