我正在学习/体验 iOS 和故事板。在 segue 期间将数据从表视图控制器传递到详细视图控制器时遇到一些问题。
CSViewDetailViewController.h
@interface CSViewTopicDetailViewController : UIViewController {
UILabel* topicTitleLabel;
UITextView* topicDescriptionTextView;
}
@property (nonatomic, strong) UILabel *topicTitleLabel;
@property (nonatomic, strong) UITextView *topicDescriptionTextView;
@end
CSListTopicsViewController.m
#pragma mark Table view selection
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([[segue identifier] isEqualToString:@"CreateTopicSegue"]) {
CSCreateTopicViewController *cvc = (CSCreateTopicViewController *)[segue destinationViewController];
cvc.delegate = self;
}
else if ([[segue identifier] isEqualToString:@"ViewTopicDetailSegue"]) {
NSLog(@"Preparing to segue to the View Topic view controller...");
CSViewTopicDetailViewController *controller = (CSViewTopicDetailViewController *)[segue destinationViewController];
NSIndexPath * indexPath = (NSIndexPath*) sender;
controller.topicDescriptionTextView.text = topic.topicDescription;
controller.topicTitleLabel.text = topic.topicTitle;
controller.title = topic.topicTitle;
NSLog(@"Set title label to: %@ from: %@", controller.topicTitleLabel.text, topic.topicTitle);
NSLog(@"Set title label to: %@ from: %@", controller.topicTitleLabel.text, topic.topicTitle);
NSLog(@"Segueing to the View Topic view controller...");
}
}
输出:
2012-05-01 13:51:01.301 ConversationStarters[42517:fb03] Preparing to segue to the View Topic view controller...
2012-05-01 13:51:01.302 ConversationStarters[42517:fb03] Set title label to: (null) from: Test topic 1
2012-05-01 13:51:01.303 ConversationStarters[42517:fb03] Segueing to the View Topic view controller...
可以看到segue被调用,行设置UILabel执行,Topic对象中的数据设置/不为空。但无论出于何种原因,UILabel 都没有存储传递给它的文本值。
有什么想法吗?提前致谢。