0

テーブルビューセルに接続されている詳細ビューコントローラがあります。私はデータモデルを持っています。それは私がそれらに必要とするすべての私の財産でありNSObject、意志を持っています。NSMutableArray

にラベルを@property付けて名前を付けましたquestionLabel。何らかの理由で、詳細ビューに移動すると、のデータモデルに入力した質問が表示されませんNSMutableArray

最初はセグエが機能していないと思っていましたが、ナビゲーションバーのタイトルを変更しようとすると、からデータを渡したときに機能しましたNSMutableArray

誰かが私のラベルで何が間違っているのか知っていますか?

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"pushDetail"])
    {
        // Create an instance of our DetailViewController
        DetailQuestionViewController *DQV = [[DetailQuestionViewController alloc] init];

        NSIndexPath *path = [self.tableView indexPathForSelectedRow];

        // Setting DQV to the destinationViewController of the seque
        DQV = [segue destinationViewController];

        Question *selectedQuestion = [self.myQuestionList questionAtIndex:path.row];

        DQV.questionLabel.text = [selectedQuestion questionName];
        DQV.navigationItem.title = [selectedQuestion questionRowName];



    }


}

更新(対象:adambinsz)

テーブルビュー

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"pushDetail"])
    {
        // Create an instance of our DetailViewController
        DetailQuestionViewController *DQV = [[DetailQuestionViewController alloc] init];

        // Setting DQV to the destinationViewController of the seque
        DQV = [segue destinationViewController];

        NSIndexPath *path = [self.tableView indexPathForSelectedRow];
        Question *selectedQuestion = [self.myQuestionList questionAtIndex:path.row];

        DQV.detailItem = selectedQuestion;



    }


}

detailView

- (void)setDetailItem:(id)newDetailItem
{
    if (_detailItem != newDetailItem) {
        _detailItem = newDetailItem;

        // Update the view.
        [self configureView];
    }
}

- (void)configureView
{
    // Update the user interface for the detail item.

    if (self.detailItem) {
        Question *theQuestion = (Question *)self.detailItem;
        self.questionLabel.text = theQuestion.questionName;

        NSLog(@"The Question's questionName is %@", theQuestion.questionName);

     }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self configureView];
}

それが機能していない可能性があると思う理由は、のifステートメントがself.detailItem正しくチェックしていないためです。

メソッドは、ではなく呼び出されdetailItemます。

4

1 に答える 1

2

テキストを設定しようとすると、ラベルがまだ作成されていない可能性があります。selectedQuestionインスタンス変数をDetailQuestionViewController作成し、View Controller を作成するときに設定します。このようなもの:

// Create an instance of our DetailViewController
DetailQuestionViewController *DQV = [[DetailQuestionViewController alloc] init];

NSIndexPath *path = [self.tableView indexPathForSelectedRow];

// Setting DQV to the destinationViewController of the seque
DQV = [segue destinationViewController];

DQV.selectedQuestion = [self.myQuestionList questionAtIndex:path.row];

そして、DetailQuestionViewController のviewDidLoadメソッドで、以下を使用してラベルのテキストを設定します。

self.questionLabel.text = [selectedQuestion questionName];
self.navigationItem.title = [selectedQuestion questionRowName];
于 2012-12-28T16:21:23.827 に答える