我有一个使用故事板的简单设置,其中一个视图控制器(MainViewController)通过委托与另一个(JoinedViewController)对话。在 prepareForSegue 之前一切都很好。在那里,我为接收视图控制器声明了 roomData 和标签的文本,但都没有收到。
主视图控制器.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"JoinRoom"]) {
UINavigationController *navigationController = segue.destinationViewController;
JoinedViewController *joinedViewController = [[navigationController viewControllers]objectAtIndex:0];
joinedViewController.label.text = self.roomName;
joinedViewController.roomData = self.roomData;
joinedViewController.delegate = self;
}
}
MainViewController.h 声明:
@interface MainViewController : UIViewController <JoinedViewControllerDelegate, UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (nonatomic, copy) NSString *roomName;
@property (nonatomic, weak) S3ListObjectsResult *roomData;
JoinedViewController.h 声明:
@interface JoinedViewController : UITableViewController
@property (nonatomic, weak) id <JoinedViewControllerDelegate> delegate;
@property (nonatomic, weak) S3ListObjectsResult *roomData;
@property (weak, nonatomic) IBOutlet UILabel *label;