私はObjective Cの初心者です。私がやっていることは、目的のView ControllerのprepareSegueにいくつかの値を設定することです。奇妙なことに、関数で NSLog をコメントアウトすると、宛先コントローラーのプロパティに値が割り当てられません。
私のコードは次のとおりです。
-(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);
}
}
項目はプロパティを持つカスタム クラスです
@property (strong, nonatomic) NSString *title;
LocateItemController には次のプロパティがあります
@property (weak, nonatomic) Item *item;
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
そしてviewDidLoadは単にアイテムを割り当てます
self.titleLabel.text = self.item.title;