2013-07-23 28 views
0

我是想通过它表现出与UITableViewController中之间的数据:的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'。

回答

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"]]; 
} 
+0

百万谢谢! :d – rulilg

0

我认为你的问题是你在显示标签之前设置标签的文本。 看看这个question问由我回答

+0

我该如何初始化它? – rulilg

+0

在infoPartidaVC上创建NSString属性设置为didSelectRowAtIndexPath中的值,在infoPartidaVC的viewDidLoad中使用字符串设置标签 –

相关问题