2013-03-04 42 views
1

我有兩個UITableViews:tableviews1和tableview2。UITableViewCell內的TableView沒有檢測到

tableview2位於tableview1的UITableViewCell中。當我在tableview2的uitableviewcell上點擊時,它沒有響應,但是tableview1 tableviewcell被檢測到。

任何人都可以幫助解決這個問題嗎?

這是代碼我使用:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (tableView == orderFoodDetailTableview) { 

    if (cell == nil) { 

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 

cell.selectionStyle = UITableViewCellSelectionStyleNone; 

    } 
} 
    else { 


cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 

    [self addUItableViewAsSubView :cell]; 

     } 

    cell.selectionStyle = UITableViewCellSelectionStyleGray; 
    } 

    return cell; 
} 



- (void)addUITableViewAsSubView:(UITableViewCell *)cell{ 

    portionSelected_yVal = [sArray count]*25; 
    portionTableview = [[UITableView alloc]initWithFrame:CGRectMake(10, height+53, 140, portionSelected_yVal)]; 
    portionTableview.delegate = self; 
    portionTableview.dataSource = self; 
    portionTableview.backgroundColor = [UIColor clearColor]; 
    portionTableview.hidden = YES; 
    portionTableview.layer.borderColor=[UIColor blackColor].CGColor; 
    portionTableview.layer.borderWidth=1.0f; 
    portionTableview.layer.cornerRadius=2.0f; 
    [cell addSubview:portionTableview]; 
} 
+0

你有沒有設置tableview2的代表? – 2013-03-04 08:21:13

+0

是的,我正在那樣做。 – user2130948 2013-03-04 08:28:27

+0

爲什麼不發佈一些相關的代碼? – 2013-03-04 08:57:43

回答

1

對於你所提到的目的(在你的註釋),您可以動態調整的TableView1UITableViewCell的高度,而用戶觸摸下來tableviewcell。再次觸摸該單元格,您可以將其恢復爲正常大小。

我希望你明白我的觀點。


編輯

你必須檢查它的tableView你想要做的UITableView的共同委託方法的動作。

對於例如你有兩個表格T1和T2。

然後在下面的方法中,你必須首先檢查對於哪個tableview(T1或T2),方法被調用。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    if (tableView == T1) 
     // Return number of sections for T1; 
    else if (tableView == T2) 
     // Return number of sections for T2; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    if (tableView == T1) 
     // Return number of rows for T1; 
    else if (tableView == T2) 
     // Return number of rows for T2; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (tableView == T1) 
     // Create and Return cell for T1; 
    else if (tableView == T2) 
     // Create and Return cell for T2; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (tableView == T1) 
     // Do stuff for T1 related actions; 
    else if (tableView == T2) 
     // Do stuff for T2 related actions; 
} 

是否清楚?

+0

是的。我已經做了,但問題是我無法檢測tableView2的委託方法。當我點擊tableView1的tableView2.Delegate方法的UITableViewCell被調用而不是tableView2時。 – user2130948 2013-03-04 10:31:17

+0

@ user2130948回答編輯 – viral 2013-03-04 11:50:25

+0

我敢肯定,你永遠不會得到適當的回調。 UITableViews有很多底層代碼處理觸摸事件。你可以做的是響應方法'tableView:willSelectRowAtIndexPath:',如果它是tableView1(頂部表格視圖)和一個包含單元格內的表格視圖的索引路徑,則返回'nil'。 – 2013-03-04 11:57:49

相關問題