0

我想开发一个 iPad 应用程序。我有一个UIViewController包含UITableViewandUIView的文件,在我的文件 .xib 中有这两个控制器。在我的ViewController.h:我有UITableView *tableUIView *viewContent

ViewController.m:我开发了需要将数据加载到表视图中的功能。现在我需要将数据从UITableView我的UIView. 我使用didSelectRowAtIndexPath但它不起作用:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ 
     // I get the object activite : here no problem 
     IPADAG1Activity  *activite = [[objects objectForKey:[objectsIndex objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
     UIView *contentView = [[UIView alloc]init ];
     //now I instanciate my UIViewController wich contain  : uiview *contentview and uitableview
     GSAActivityViewController *activity = [[GSAActivityViewController alloc]init];
     //in uiview I add label "desc" that I affect the value of activite.DESCRIPTION
     activity.desc.text = activite.DESCRIPTION;
}
4

3 回答 3

0
IPADAG1Activity  *activite = [[objects objectForKey:[objectsIndex objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];

您是否在 active.DESCRIPTION 中获取数据

问题就在这里

 GSAActivityViewController *activity = [[GSAActivityViewController alloc]init];
 //in uiview I add label "desc" that I affect the value of activite.DESCRIPTION
activity.desc.text = activite.DESCRIPTION;

您尚未将 activity.view 添加到 self.view。

于 2013-05-03T13:03:36.473 回答
0

您需要设置tableViews delegate

self.tableView.delegate = self;

或者,您可以在 IB 中这样做:

在此处输入图像描述

于 2013-05-03T13:04:15.123 回答
0

我假设这段代码是你GSAActivityViewController班级的一部分。话虽如此,您不需要GSAActivityViewController在该控制器上创建新标签并更改标签,因为您已经初始化了控制器。

这是您的代码正在执行的操作:

 //This line is getting your IPADAG1Activity correctly it looks like, this is fine
 IPADAG1Activity  *activite = [[objects objectForKey:[objectsIndex objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];


 //This code is creating a brand new UIView called *contentView, but it never gets used.  I am guessing that you are getting a warning about an unused variable here. ?  This line does not need to be in the program as far as I can tell because you don't need to create a new contentView, you just need to use the on GSAActivityViewController
 UIView *contentView = [[UIView alloc]init ];


 //The line below is creating a brand new instance of GSAActivityViewController, but you don't want a brand new isntance, you want to use this GSAActivityViewController that has already been initialized.  This line does not need to be in the program as fas as I can tell.
 //now I instanciate my UIViewController wich contain  : uiview *contentview and uitableview
 GSAActivityViewController *activity = [[GSAActivityViewController alloc]init];


 //Lastly, you are changing the text of desc on the new GSAActivityViewController that you created.  This controller did not need to be created and is not being used in any way other than this function block, so when you change the text on desc you are changing the text on something that has not been displayed and is just about to get tossed out when this function ends (Assuming ARC)
 //in uiview I add label "desc" that I affect the value of activite.DESCRIPTION
 activity.desc.text = activite.DESCRIPTION;

因此,要解决您的问题,您可以使用self来获取当前的GSAActivityViewController. 您不需要初始化一个新的(或一个新的contentView)。

所以你的代码应该是这样的:

 IPADAG1Activity  *activite = [[objects objectForKey:[objectsIndex objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];

 //in uiview I add label "desc" that I affect the value of activite.DESCRIPTION
 self.desc.text = activite.DESCRIPTION;

该答案基于一些假设,主要desc是作为属性的标签,GSAActivityViewController并且此代码位于GSAActivityViewController.

于 2013-05-03T16:35:54.650 回答