iOS5:在segue期间未将数据传递给UI对象

时间:2012-05-01 19:59:17

标签: xcode ios5

我正在学习/试验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对象中的数据设置为/不为null。但无论出于何种原因,UILabel都不存储传递给它的文本值。

有什么想法?提前谢谢。

0 个答案:

没有答案