Iphone 将NSString从视图传递到另一个视图

Iphone 将NSString从视图传递到另一个视图,iphone,nsstring,Iphone,Nsstring,我正在尝试将NSString传递给另一个视图 在我的第一个视图(是地图视图)中,我的代码是: FirstView.m文件: 导入“FlipsideViewController.h” -(iAction)显示详细信息:(id)发件人{ } 然后NSlog打印正确的字符串。但当我尝试将该字符串传递给我的第二个名为details的ViewController字符串时: 在my FlipsideViewController.h中定义: NSString*详细信息 @属性(非原子,强)NSString*详

我正在尝试将NSString传递给另一个视图

在我的第一个视图(是地图视图)中,我的代码是:

FirstView.m文件:

导入“FlipsideViewController.h” -(iAction)显示详细信息:(id)发件人{

}

然后NSlog打印正确的字符串。但当我尝试将该字符串传递给我的第二个名为details的ViewController字符串时:

在my FlipsideViewController.h中定义:

NSString*详细信息

@属性(非原子,强)NSString*详细信息

在FlipsideViewController.m中时

@synthesize fetchStr;
@综合细节//每当我放入日志时,它都会打印空值

值:NSLog(@“************detalli%@”,detalli)


我的错在哪里?

在secondViewController中添加一个属性,一个NSString类型的保留属性 有关添加属性的信息,请阅读以下内容

请编辑此部分

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]; 

尝试以下步骤:- 1) 首先,在另一个ViewController.h中创建属性

@property (nonatomic, strong ) NSString *fetchStr;
2) 在另一个ViewController.m中合成NSString

@synthesize fetchStr;
3) 在firstViewController中使用

anotherViewController *avc =  [[anotherViewController alloc]init];
avc.fetchStr = ann.name;
并在另一个ViewController中打印(NSLog)fetchStr

@property(nonatomic,retain) MyLocation *annotation;
然后将其传递给另一个视图控制器


它会起作用。

向我们展示了如何将字符串传递给第二个ViewControllerHi iArezki,NSlog在同一个函数中返回null值。在第二个视图中,我定义了属性@property(非原子,保留)NSString*details;您提到了吗?是的,所以现在当您要移动到secondview时,必须首先调用secondview.details=annotation.name;我试过了,但没用。在第一个视图NSLog(@“value:%@”,secondView.details);->返回正确的值,但在第二个视图中:NSLog(@“value:%@”,详细信息);return->nullview如何使secondview可见?请发布一些代码,为什么要分配一个新的视图控制器?为什么将此部分称为FlipsideViewController*控制器=[[FlipsideViewController alloc]initWithNibName:@“详细信息”捆绑包:nil];controller.delegate=self;controller.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;[self-presentModalViewController:控制器已设置动画:是];[控制器释放];谢谢,它起作用了。我没有初始化另一个ViewController方法!。。。但仅在第一个视图中。在第二个视图中(我需要fetchStr),NSlog返回null…如果在xcode 4.0中工作,那么使用这个avc.fetchStr=[ann.name retain];我在xcode 4.2上工作。我在第一个视图中尝试了avc.fetchStr=[ann.name retain],但在第二个视图中,fetchStr保持为空:s首先在firstViewController中打印NSLog(@%@),ann.name
@property(nonatomic,retain) MyLocation *annotation;