2013-05-03 41 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

相關問題