我在尝试将联系人(loggedinUser)的信息传递给destinationViewControllers的联系人(currentUser)时创建了一个segue,但由于某种原因它没有通过。下面的代码有问题吗?
原图:
...
self.loggedInUser.firstName = @"first name";
self.loggedInUser.lastName = @"last name";
self.loggedInUser.company = @"company"
self.loggedInUser.position = @"position";
[self performSegueWithIdentifier:@"profileSegue" sender:self];
...
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
ProfileViewController *pvc = (ProfileViewController *) [segue destinationViewController];
pvc.currentUser = self.loggedInUser; }
然后我在 DestinationViewController 的标签中显示值:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSString *fullName = [NSString stringWithFormat:@"%@ %@", currentUser.firstName, currentUser.lastName];
fullNameLabel.text = fullName;
companyLabel.text = currentUser.company;
positionLabel.text = currentUser.position;
}
loggedInUser 和 currentUser 都属于“Contact”类型。但标签最终显示为空。我错过了一些明显的东西吗?
编辑
这是 self.loggedinUser 没有被传递给 prepareForSegue 的问题。
标头代码:
#import "Contact.h"
@interface LoginViewController : UIViewController
{
}
...
@property (nonatomic, retain) Contact *loggedInUser;