Pass a string between 2 view controllers
My problem is quite simple, but as a beginner, I'm lost :D
I have to view controller :
view one call view 2 like this :
self.FacebookTypeRequest =@"favoris";
FaceBookViewController *viewcontrol = [[FaceBookViewController alloc]initWithNibName:@"FaceBookViewController" bundle:[NSBundle mainBundle]];
viewcontrol.title = @"FaceBook";
[self.navigationController pushViewController:viewcontrol animat开发者_运维技巧ed:YES];
[viewcontrol release];
How can I send my string facebookTypeRequest to my view controller 2 ?
Make a property on your second view controller (FaceBookViewController) like this in the .h file :
@interface FaceBookViewController {
...
NSString *facebookTypeRequest;
...
}
@property (nonatomic, copy) NSString *facebookTypeRequest;
and in the .m file put
@implementation FaceBookViewController
@synthesize facebookTypeReqeust;
and remember to put in your dealloc method
- (void) dealloc {
[facebookTypeRequest release];
// release other properties here as well
[super dealloc];
}
Then, you can just set it like this :
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];
Now, inside your FaceBookViewController you have the facebookTypeRequest.
Hope that helps.
NB It's generally bad practice to use captial letters to start the name of a property i.e. self.FaceboookTypeReqeust should really be self.facebookTypeRequest.
精彩评论