2013-10-21 37 views
0

我有一個表視圖藿使自動取消選擇的tableview細胞

,當我點擊細胞一切都好

然而,當我從手機中刪除我的手指,細胞會保持選定

我怎樣才能使當用戶停止觸摸特定小區和不接觸其他細胞

+0

保持選中狀態意味着您的單元格保持藍色狀態? –

回答

0

你必須設置的風格cellForRowAtIndexPath或改變細胞中willSelectRowAtIndexPath和變回它變成不被選中。 例如

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // ... 
    cell.selectionStyle = UITableViewCellSelectionStyleBlue; // or an other style 
    // ... 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // ... 
    [tableView deselectRowAtIndexPath:indexPath animated:NO]; 
    // ... 
} 
+0

這不起作用 - 單元格不顯示被選中的指示,我想要顯示選擇,但我希望選擇消失,當用戶停止觸摸桌面視圖時 – alex440

+0

我沒有在iOS7中嘗試過,但在6.1上它按照你所描述的運行。我觸摸細胞,它顯示出藍色。我釋放觸摸(觸摸)和選擇消失 – geo

1

簡單:

在該方法中:didSelectRowAtIndexPath

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

    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    } 
+0

不是那麼簡單:(請檢查其他評論請 – alex440

+0

這應該工作。我也檢查了IOS7以及檢查你的代碼完整的UItableView代表。 –

0

放入的UITableView代表以下。

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
     UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
     [cell setSelected:NO animated:YES]; 
    } 
+0

這不起作用 - 它刪除了細胞曾經被選中的指示 - 我想顯示細胞被選中,但第二個用戶將他的手指從細胞中取出,我想取消它 – alex440

0

您是否考慮處理觸摸事件?

例如:添加一個UITapGestureRecognizer,使用-(CGPoint)locationInView:(UIView *)view方法檢測正在觸摸哪個單元格。在觸摸開始時將單元格標記爲選中狀態,並在觸摸結束時將其標記爲取消選中狀態。

0

你把委託給UITableView了嗎?

self.tableView.delegate = self; 

這就是爲什麼您遇到此

這不起作用 - 細胞不顯示選擇

0

tableView:didSelectRowAtIndexPath:是 的指示,設置所選屬性使用方法setSelected:animated:將該單元格設置爲NO

E.g.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath]; 
    [cell setSelected:NO animated:YES]; 
} 

注:

設置細胞的選定的屬性= NO和動畫= YES用上述方法將導致隔膜消失。我發現繞過這個的唯一方法是設置動畫=否,但是,如果我找到另一種方式,我會更新我的答案。