我有一个简单的设置,使用storyboard,一个viewcontroller(MainViewController)通过委托与另一个(JoinedViewController)对话。在准备之前,一切都很好。在那里,我声明了roomData和接收视图控制器的标签文本,但都没有收到。
MainViewController.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 decarations:
@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;
答案 0 :(得分:1)
我认为你有两个不同的问题。 roomData应声明为strong,而不是弱(在两个类中)。 roomName的问题不是字符串本身,而是在JoinedViewController的viewDidLoad调用之前你试图在标签上设置它的事实。在加载视图之前,您无法访问其他控制器的UI元素。您应该传递字符串roomData,并在JoinedViewController的viewDidAppear方法中将其设置在标签上。