2014-07-20 116 views
0

我對錶格視圖單元格view1和view2有2個視圖,我想要做的是當我點擊一個單元格時,我希望view1被隱藏並且view2被顯示(在開始view1被顯示,view2被隱藏),我用視圖view1 = 102和view2 = 103的標籤,出於某種原因,我無法確定,view1被隱藏,但view2不被顯示。修改UITableView中didSelectRowAtIndexPath上的單元格

這裏是我的代碼:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 


    UIView * view1 = (UIView *)[cell viewWithTag:102]; 
    UIView * view2 = (UIView *)[cell viewWithTag:103]; 

    [view1 setHidden:YES]; 
    [view2 setHidden:NO]; 


    NSLog(@"View 2 is : %hhd",view2.hidden); 


} 

故事板 enter image description here

模擬器

enter image description here

回答

6

,而不是

cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 

使用

cell = [tableView cellForRowAtIndexPath:indexPath]; 

因爲dequeueReusableCellWithIdentifier: forIndexPath:將返回當前不可見當前未使用的表格單元格。

相關問題