我是 iOs 编程的初学者。我有一些问题。我有 MasterViewController,代码如下
#import "MasterViewController.h"
#import "DetailViewController.h"
@interface MasterViewController () {
}
@property (strong, nonatomic) NSString *str;
@end
@implementation MasterViewController
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.str = @"1234";
}
我将属性“str”发送到 DetailViewController。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSString *object = self.str;
[[segue destinationViewController] setDetailItem:object];
}
}
之后,我改变 str
#import "DetailViewController.h"
@interface DetailViewController ()
@end
@implementation DetailViewController
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.detailItem = @"1233";
}
之后,我回到 MasterViewController 但 str 没有改变。为什么?