0

次のように表示される UITableViewController 間でデータを渡そうとしました:

SeleccionBundesligaViewController *seleccionBundesligaVC = [[SeleccionBundesligaViewController alloc]initWithStyle:UITableViewStylePlain];

seleccionBundesligaVC.title = @"1.Bundesliga";
[self.navigationController pushViewController:seleccionBundesligaVC animated:YES];

行を選択すると、次のように閉じられます。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic = [equipos objectAtIndex:indexPath.row];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
    InformacionPartidaViewController *infoPartidaVC = [storyboard instantiateViewControllerWithIdentifier:@"infoPartidaVC"];
    [self.navigationController popViewControllerAnimated:YES];
    [infoPartidaVC.labelNombreEquipo setText:[dic objectForKey:@"nombre"]];

}

しかし、行を選択すると、「infoPartidaVC」にデータが渡されません。

4

2 に答える 2

1

最善の策は、SeleccionBundesligaViewController の .h ファイルにプロパティを作成することです。

@property (weak, nonatomic) InformacionPartidaViewController *infoPartidaVC;

UITableViewController を作成してプッシュする前に、参照を追加します。

SeleccionBundesligaViewController *seleccionBundesligaVC = [[SeleccionBundesligaViewController alloc]initWithStyle:UITableViewStylePlain];

seleccionBundesligaVC.title = @"1.Bundesliga";
seleccionBundesligaVC.infoPartidaVC = self;
[self.navigationController pushViewController:seleccionBundesligaVC animated:YES];

次に、UITableViewController の didSelectRowAtIndexPath で:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic = [equipos objectAtIndex:indexPath.row];

    [self.navigationController popViewControllerAnimated:YES];
    [self.infoPartidaVC.labelNombreEquipo setText:[dic objectForKey:@"nombre"]];
}
于 2013-07-23T22:40:38.867 に答える
0

あなたの問題は、ラベルが表示される前にラベルのテキストを設定していることだと思います。私が答えたこの質問を見てください

于 2013-07-23T22:28:20.013 に答える