Ios UITableViewController不是';t传递数据
我试图在UITableViewController之间传递数据,该控制器显示为:Ios UITableViewController不是';t传递数据,ios,uiviewcontroller,uitableview,Ios,Uiviewcontroller,Uitableview,我试图在UITableViewController之间传递数据,该控制器显示为: SeleccionBundesligaViewController *seleccionBundesligaVC = [[SeleccionBundesligaViewController alloc]initWithStyle:UITableViewStylePlain]; seleccionBundesligaVC.title = @"1.Bundesliga"; [self.navigationContro
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”。我认为您的问题在于,您正在显示标签之前设置标签的文本。
请看我回答的问题您最好在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"]];
}
如何初始化?在infoPartidaVC上创建一个NSString属性,设置didSelectRowatineXpath中的值,在infoPartidaVC的viewDidLoad中使用该字符串设置标签