我正在尝试将 NSString 传递给另一个视图。
在我的第一个视图(是地图视图)中,我的代码是:
FirstView.m 文件:
导入“FlipsideViewController.h”
-(IBAction) displayDetails:(id) 发件人{
MyLocation *ann = [_mapView.selectedAnnotations objectAtIndex:([_mapView.selectedAnnotations count]-1)]; FlipsideViewController *flipsideViewController; flipsideViewController= [[FlipsideViewController alloc]init]; flipsideViewController.details =ann.name; NSLog(@"ann.name:%@", ann.name); NSLog(@"details:%@", flipsideViewController.details); FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"details" bundle:nil]; controller.delegate = self; controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:controller animated:YES]; [controller release];
}
并且 NSlog 打印正确的字符串。但是,当我尝试将该字符串传递给名为 details 的 SecondViewController 字符串时:
在我的 FlipsideViewController.h 中定义:
NSString *详细信息;
@property (nonatomic, strong) NSString *details;
在 FlipsideViewController.m 中
@synthesize 详细信息;//每当我输入日志时,它都会打印空值
值:NSLog(@" * ** * ** * ** * *** *detalli %@",detalli);
我的错在哪里?