2013-05-03 39 views
0

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

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

你是否试图创建一个新的viewController并将其添加到tableView行或者你试图访问另一个视图上的viewController? – 2013-05-03 13:07:27

+0

看来你需要简单地向viewController添加一个新的视图,而不是创建一个新的viewController来保存视图。 – 2013-05-03 13:09:04

+0

@MarkM:我不明白你的意思 – 2013-05-03 13:32:21

回答

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内。

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; 

你还没有加入活动.view到self.view。

+0

即使我昌它由一个字符串:@“价值”,标签这么想的利用这个值 – 2013-05-03 13:08:21

+0

活动代表我的包含整个的UIViewController:的UIView和UITableView的 – 2013-05-03 13:12:30

+0

那么就没有必要创建同一类的另一个目标 – 2013-05-03 13:14:07

0

你需要设置tableView小号delegate

self.tableView.delegate = self; 

或者,你可以在IB这样做:

enter image description here

+0

是的,我做到了,我的问题不在于显示数据到我的表中,这是完成的。现在我需要将这些数据传递给我的uiview – 2013-05-03 13:06:36

+0

@MMerou您是使用静态表还是原型表? – Undo 2013-05-03 13:08:20

+0

prototype table。请原谅我的plz数据显示在tableview中,所以我不认为问题在于如何显示数据,我想我错过了didselectedrowatindex方法中的一些东西 – 2013-05-03 13:10:54

相关问题