我的问题很简单,但是作为一个初学者,我迷路了:D
我必须查看控制器:
查看一个呼叫视图2像这样:
self.FacebookTypeRequest =@"favoris";
FaceBookViewController *viewcontrol = [[FaceBookViewController alloc]initWithNibName:@"FaceBookViewController" bundle:[NSBundle mainBundle]];
viewcontrol.title = @"FaceBook";
[self.navigationController pushViewController:viewcontrol animated:YES];
[viewcontrol release];
如何将字符串facebookTypeRequest发送到视图控制器2?
最佳答案
在.h文件中,在第二个视图控制器(FaceBookViewController)上设置一个属性,如下所示:
@interface FaceBookViewController {
...
NSString *facebookTypeRequest;
...
}
@property (nonatomic, copy) NSString *facebookTypeRequest;
并在.m文件中
@implementation FaceBookViewController
@synthesize facebookTypeReqeust;
并记得放入您的dealloc方法
- (void) dealloc {
[facebookTypeRequest release];
// release other properties here as well
[super dealloc];
}
然后,您可以像这样设置它:
self.FacebookTypeRequest = @"favoris";
FaceBookViewController *viewcontrol = [[FaceBookViewController alloc] initWithNibName:@"FaceBookViewController" bundle:nil];
viewcontrol.title = @"FaceBook";
viewcontrol.facebookTypeRequest = self.FacebookTypeRequest; //!< This is the line :)
[self.navigationController pushViewController:viewcontrol animated:YES];
[viewcontrol release];
现在,在FaceBookViewController内部,您具有facebookTypeRequest。
希望能有所帮助。
注意:使用大写字母开头的属性名称即self。通常是一种不好的做法.FaceboookTypeReqeust应该实际上是self.facebookTypeRequest。
关于ios - 在2个 View Controller 之间传递字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2928360/