2012-10-13 94 views
3

UITableViewCell becomes unresponsive這是一個非常不同的問題,有一個非常不同的解決方案。UITableView變得沒有反應

我的tableView是UIViewController中的一個子視圖,最初工作正常,我可以選擇表中的單個行。但是,當在屏幕底部顯示一行時(彈出窗口是UIView),我創建了自己的彈出窗口。當這個彈出窗口中,我還創建了另一個UIView,它覆蓋了彈出窗口後面的屏幕,並使背景變暗。發生的第三件事是我創建了一個UITapGestureRecogniser來跟蹤用戶的水龍頭,並且如果他們在UIView外部輕按,那麼將移除兩個UIViews和TapGestureRecogniser並調用deselectRowAtIndex ...方法。

但是,在這一點上,我不能使用tableView,因爲我希望能夠在tableView中選擇不同的字符串,並彈出窗口再次出現(彈出窗口最終將包含將啓用用戶的鏈接移動到不同的viewControllers)。

我試圖重新加載數據,刪除tableview並替換它,編輯didSelectRowAtIndex,刪除deselectRowAtIndex方法,但沒有我試過似乎工作,我無法找到任何東西在stackoverflow上,因爲我的問題似乎是非常具體(雖然我很抱歉如果有東西在那裏)。

我會添加我的代碼幾部分,但是,我不知道問題出在哪裏,我可能沒有複製在右部。

刪除開銷是從選擇方法tapGesture

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


    if(_popOverView == nil) 
    { 
    _popOverView = [[UIView alloc]initWithFrame:CGRectMake(20, 200, 280, 150)]; 

    _popOverView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"wood.jpeg"]]; 
    } 
    if(_mask == nil) 
    { 
     _mask = [[UIView alloc] initWithFrame:self.view.frame]; 
     [_mask setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.78]]; 
    } 

    if (_tapDetector == nil) 
    { 
     _tapDetector= [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(removeOverHead:)]; 
    } 


    [self.view addSubview:_mask]; 
    [self.view addSubview:_popOverView]; 
    [self.view addGestureRecognizer:_tapDetector]; 


} 



-(void) removeOverHead:(UITapGestureRecognizer*) sender 
{ 

    CGPoint locationOfTap = [_tapDetector locationInView:self.view]; 


    if (locationOfTap.y < (200 + 150) && locationOfTap.y > 200 && locationOfTap.x > 20 && locationOfTap.x < (20 + 280)) { 


    NSLog(@"%f,%f",[_tapDetector locationInView:self.view].x,[_tapDetector locationInView:self.view].y); 

    } 

    else 
    { 

     [_mask removeFromSuperview]; 
     [_popOverView removeFromSuperview]; 
     [_tapDetector removeTarget:self action:@selector(removeOverHead:)]; 



     /*this idea doesn't work :(
     [self.tableView removeFromSuperview]; 
     [self.view addSubview:_tableView];*/ 



    } 
} 

我真的很希望答案在這裏,很簡單,並且提前感謝您花時間閱讀本文。

回答

1

解決了!對不起,浪費你的時間。這是gestureRecogniser的錯誤刪除方法。我換成

[_tapDetector removeTarget:self action:@selector(removeOverHead:)] 

[self.view removeGestureRecognizer:_tapDetector] 

爲UIGestureRecogniser是揮之不去和阻礙的tableView!

0

如果你在該刪除方法的else塊內部插入一個斷點或NSLog(),你會進入它嗎?

聽起來像你的if語句可能關閉。你應該使用CGRectContainsPoint()。但是,如果我理解正確,那麼當用戶點擊調暗背景視圖時,您正嘗試解除所有內容。您可以使該視圖成爲一個按鈕,或者您可以將觸摸的視圖指針與指向背景視圖的指針進行比較。

+0

當我觸摸調光背景時,這三個對象消失,所以它進入else子句。然後,我可以上下滾動tableView,並且當我使用deslectRow函數時,它將取消選擇tableView中的行,但從那時起,我無法選擇任何東西。 – Rambatino

+0

這個問題,是要去除tapGesture,我不認爲它正在被正確刪除:s – Rambatino

+1

解決了它!對不起,浪費你的時間。這是gestureRecogniser的錯誤刪除方法。我用[self.view removeGestureRecognizer:_tapDetector]替換了[_tapDetector removeTarget:self action:@selector(removeOverHead :)],因爲UIGestureRecogniser徘徊並阻礙了tableView! – Rambatino