Reputation: 3545
I am trying to pass values (UIImage, NSString) to another ViewController, but it wont work.
My code looks like this:
1st ViewController.m
#import 2nd ViewController.h
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
AppDetail *advc = [[AppDetail alloc] init];
if ([[segue identifier] isEqualToString:@"showDetail"]) {
advc.appTitel = name;
advc.appIcon = icon;
advc.detailAppName = detileName;
advc.appDescription = description;
}
}
2nd ViewController.h
#import <UIKit/UIKit.h>
@interface AppDetail : UIViewController
@property (strong, nonatomic) NSString *appTitel;
@property (strong, nonatomic) UIImage *appIcon;
@property (strong, nonatomic) NSString *detailAppName;
@property (strong, nonatomic) NSString *appDescription;
@end
2nd ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = self.appTitel;
self.appIconImageView.image = self.appIcon;
self.detailAppNameTextView.text = self.detailAppName;
self.appDescriptionTextView.text = self.appDescription;
}
But I always get (null)
for all values!
What am I doing wrong??
Upvotes: 0
Views: 61
Reputation: 8247
Correct by this :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
// Get reference to the destination view controller
AppDetail *advcc = [segue destinationViewController];
advc.appTitel = name;
advc.appIcon = icon;
advc.detailAppName = detileName;
advc.appDescription = description;
}
}
The code below it's when you don't use storyboard :
AppDetail *advc = [[AppDetail alloc] init];
Upvotes: 2
Reputation: 9836
Correct these lines
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
//AppDetail *advc = [[AppDetail alloc] init];
if ([[segue identifier] isEqualToString:@"showDetail"]) {
AppDetail *advc = segue.destinationViewController; //ADD THIS
advc.appTitel = name;
advc.appIcon = icon;
advc.detailAppName = detileName;
advc.appDescription = description;
}
}
Upvotes: 1