2012-08-16 27 views
0

我有行的表格視圖...選擇一個項目後我想用新的數據源顯示tableView。更改選定行後的tableView的數據源

我試圖執行:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

[self.searchDisplayController setActive:YES animated:YES]; 
    Game *game = [self.filteredListContent objectAtIndex:indexPath.row]; 
    //name your class names with capitals 
    NSMutableArray *arrayToBeAdded= [[NSMutableArray alloc]initWithArray:newgamearray]; 
    [ListContent removeAllObjects]; 
    [ListContent addObject:arrayToBeAdded]; 

,但我得到exeption在init的

[ListContent removeAllObjects]; 

實現:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellID = @"cellSgames"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID]; 

    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID] autorelease]; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 

    Gmage *game = [self.ListContent objectAtIndex:indexPath.row]; 

在.h文件我宣佈:

NSArray AllList; 
NSMutableArray ListContent; 

有什麼想法?

+0

爲什麼你想顯示一個新的數據源tableView? – freelancer 2012-08-16 07:38:10

+0

選擇一個項目後,我想展示他的孩子項目 – vadim 2012-08-16 07:46:14

+0

@vadim你會得到哪些例外? ListContent在哪裏聲明?它是什麼? – 2012-08-16 07:55:28

回答

3

而不是操縱當前列表,創建新的UITableViewController與您所需的數據源。如果您使用UINavigationController,它將創建更好的用戶體驗,並且您將避免當前的問題。

例子:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    InnerTableViewController *innerTVC = [[InnerTableViewController alloc] initWithNibName:@"InnerTableViewController" bundle:nil]; 

    [self.navigationController pushViewController:innerTVC animated:YES]; 
    [innerTVC release]; 
} 
+0

我希望它在同一個表/視圖上更改而不改變視圖...我希望它能夠快速工作。 – vadim 2012-08-16 07:48:07

+0

我personaly認爲你不會得到更快的結果通過操作dataSource,因爲你仍然需要刪除,並更新列表和跟蹤一個大控制器類的一切。但是,如果這是您的選擇,讓我知道什麼是ListContent並顯示您的代碼初始化它的位置。 – Cyprian 2012-08-16 07:51:58

+0

@vadim你不會像你試圖做的那樣很快得到它。推到新的tableviewcontroller實例是要走的路。 – 2012-08-16 07:53:21

0

一般來說,如果你是在復位方法didselect數組並重新加載新的內容應該工作,你的表視圖。

在你的情況,我認爲在行: [ListContent removeAllObjects];

ListContent不是有效的指針。我沒有看到有理由在這裏崩潰。

+0

另外1件事情:[ListContent addObject:arrayToBeAdded];你應該這樣做:[Li​​stContent addObjectsFromArray:arrayToBeAdded]; – Amit 2012-08-16 09:36:26

+0

當它來到那些行然後停止在主要之前的int retVal = UIapplicationMain ... – vadim 2012-08-16 11:07:28

+0

共享的代碼是不足以告訴究竟是什麼問題,但你可以嘗試在一個簡單的應用程序中實現類似的方式,解決問題。我已經嘗試過這樣,它爲我工作。 – Amit 2012-08-16 11:24:44

相關問題