Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

MasterViewController.m

#import "DetailViewController.h"

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
    if ([segue.identifier isEqualToString:@"DetailViewControllerSeque"]) {
        DetailViewController *detailView = [segue destinationViewController];

        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

        theList = [app.listArray objectAtIndex:indexPath.row];

        detailView.theList = theList;

        // String to pass to DetailViewController
        detailView.string2pass = @"this is a passing string";
    }
}


DetailViewController.h

NSString *string2pass;

@property (retain, nonatomic) NSString *string2pass;


DetailViewController.m

NSLog(@"%@", string2pass);

Output: (null)


What I am doing wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
143 views
Welcome To Ask or Share your Answers For Others

1 Answer

Unless you have this in your implementation, it won't work as you expected.

@synthesize string2pass = string2pass;

..or you can fix it by deleting the line:

NSString *string2pass;

Your log is logging the value of string2pass variable you declared. But there is another variable _string2pass.

NSLog(@"%@", string2pass);

The @property you declared, is backed by a variable name _string2pass if you don't explicitly write a @synthesize statement. Not writing an @sythesize statement is the same as declaring one like so:

@synthesize string2pass = _string2pass;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...