开发者

NSString value not retained

I'm trying to assign data from a string to another string within a different viewcontroller however it seems that the data is not retained - i g开发者_StackOverflow社区et a null response in NSLog. I would like to know why, thanks ..


Try changing the order a bit, as below, and use retain instead of copy:

SchoolDetailViewController *schoolController = [[SchoolDetailViewController alloc]initWithNibName:nil bundle:nil];
schoolController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
schoolController.courseDetails = @"passing new content"; 
[self presentModalViewController:schoolController animated:YES];
NSLog(@" %@",schoolController.courseDetails); // 'passing new content' is shown

.h
    NSString *courseDetails;
@property (nonatomic, retain) NSString *courseDetails; 

.m
@synthesize courseDetails; 

- (void)viewDidLoad {

    NSLog(@" text : %@",courseDetails); // returns null ... why? 

    [super viewDidLoad];
}

This should work.


Well that is because the viewDidLoad method is called when you present the view controller with or without animation.

So just flip these 2 statements

[self presentModalViewController:schoolController animated:YES];
schoolController.courseDetails = @"passing new content"; 

like this

schoolController.courseDetails = @"passing new content"; 
[self presentModalViewController:schoolController animated:YES];

And then check the results once again...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜