I am a newbie to Objective C. What I am doing is setting some values in prepeareSegue for destination view controller. Strange thing is if I comment out NSLog in the function then value to destination controller’s property is not assigned.
My code for it is:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"ShowItemOnMap"] ) {
LocateItemViewController *lic = [segue destinationViewController];
NSIndexPath *index = [self.tableView indexPathForSelectedRow];
// self.itemsToBuy is a array of NSDictionary
NSDictionary *selectedItem = [self.itemsToBuy objectAtIndex:[index row]];
Item *theItem = [[Item alloc] init];
NSString *theTitle = [[NSString alloc] initWithString:[selectedItem valueForKey:@"title"]];
theItem.title = theTitle;
lic.item = theItem;
// commenting out NSLog make self.irem in LocateItemViewController nil
// and no value is shown at screen
NSLog(@"%@", lic.item.title);
}
}
Item is a custom class with property
@property (strong, nonatomic) NSString *title;
LocateItemController has following properties
@property (weak, nonatomic) Item *item;
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
and viewDidLoad simply assigns item
self.titleLabel.text = self.item.title;
If you need item to be retained, you should make it a strong property.